code: def _check_rows(rows, check, in_range=True, return_test='any'):
      
      valid_checks = set(['up', 'lo', 'year'])
      if not set(check.keys()).issubset(valid_checks):
          msg = 'Unknown checking type: {}'
          raise ValueError(msg.format(check.keys() - valid_checks))
  
      where_idx = set(rows.index[rows['year'] == check['year']]) \
          if 'year' in check else set(rows.index)
      rows = rows.loc[list(where_idx)]
  
      up_op = rows['value'].__le__ if in_range else rows['value'].__gt__
      lo_op = rows['value'].__ge__ if in_range else rows['value'].__lt__
  
      check_idx = []
      for (bd, op) in [('up', up_op), ('lo', lo_op)]:
          if bd in check:
              check_idx.append(set(rows.index[op(check[bd])]))
  
      if return_test is 'any':
          ret = where_idx & set.union(*check_idx)
      elif return_test == 'all':
          ret = where_idx if where_idx == set.intersection(*check_idx) else set()
      else:
          raise ValueError('Unknown return test: {}'.format(return_test))
      return ret
docs: Check all rows to be in/out of a certain range and provide testing on
      return values based on provided conditions
  
      Parameters
      ----------
      rows: pd.DataFrame
          data rows
      check: dict
          dictionary with possible values of 'up', 'lo', and 'year'
      in_range: bool, optional
          check if values are inside or outside of provided range
      return_test: str, optional
          possible values:
              - 'any': default, return scenarios where check passes for any entry
              - 'all': test if all values match checks, if not, return empty set