def nearest_unequal_elements(dts, dt):
 if (not dts.is_unique):
  raise ValueError('dts must be unique')
 if (not dts.is_monotonic_increasing):
  raise ValueError('dts must be sorted in increasing order')
 if (not len(dts)):
  return (None, None)
 sortpos = dts.searchsorted(dt, side='left')
 try:
  sortval = dts[sortpos]
 except IndexError:
  return (dts[(-1)], None)
 if (dt < sortval):
  lower_ix = (sortpos - 1)
  upper_ix = sortpos
 elif (dt == sortval):
  lower_ix = (sortpos - 1)
  upper_ix = (sortpos + 1)
 else:
  lower_ix = sortpos
  upper_ix = (sortpos + 1)
 lower_value = (dts[lower_ix] if (lower_ix >= 0) else None)
 upper_value = (dts[upper_ix] if (upper_ix < len(dts)) else None)
 return (lower_value, upper_value)

def nearest_unequal_elements ( dts , dt ) : if ( not dts . is_unique ) : raise ValueError ( 'dts must be unique' ) if ( not dts . is_monotonic_increasing ) : raise ValueError ( 'dts must be sorted in increasing order' ) if ( not len ( dts ) ) : return ( None , None ) sortpos = dts . searchsorted ( dt , side = 'left' ) try : sortval = dts [ sortpos ] except IndexError : return ( dts [ ( - 1 ) ] , None ) if ( dt < sortval ) : lower_ix = ( sortpos - 1 ) upper_ix = sortpos elif ( dt == sortval ) : lower_ix = ( sortpos - 1 ) upper_ix = ( sortpos + 1 ) else : lower_ix = sortpos upper_ix = ( sortpos + 1 ) lower_value = ( dts [ lower_ix ] if ( lower_ix >= 0 ) else None ) upper_value = ( dts [ upper_ix ] if ( upper_ix < len ( dts ) ) else None ) return ( lower_value , upper_value )
find values in dts closest but not equal to dt .