Allow passing df that has no idxmax or idxmin

This commit is contained in:
rasmusthog 2022-10-23 13:48:02 +02:00
parent 90168e4f1f
commit d617e50cda

View file

@ -179,7 +179,15 @@ def find_neighbours(value, df, colname, start=0, end=-1):
lower_df = df[df[colname] < value][colname] lower_df = df[df[colname] < value][colname]
upper_df = df[df[colname] > value][colname] upper_df = df[df[colname] > value][colname]
if not lower_df.empty:
lowerneighbour_ind = lower_df.idxmax() lowerneighbour_ind = lower_df.idxmax()
else:
lowerneighbour_ind = np.nan
if not upper_df.empty:
upperneighbour_ind = upper_df.idxmin() upperneighbour_ind = upper_df.idxmin()
else:
upperneighbour_ind = np.nan
return [lowerneighbour_ind, upperneighbour_ind] return [lowerneighbour_ind, upperneighbour_ind]