From d617e50cdafd2ab3d5b88b5bb6223cd4c4e4c9de Mon Sep 17 00:00:00 2001 From: rasmusthog Date: Sun, 23 Oct 2022 13:48:02 +0200 Subject: [PATCH] Allow passing df that has no idxmax or idxmin --- nafuma/auxillary.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nafuma/auxillary.py b/nafuma/auxillary.py index 9d30948..1cc6f24 100644 --- a/nafuma/auxillary.py +++ b/nafuma/auxillary.py @@ -179,7 +179,15 @@ def find_neighbours(value, df, colname, start=0, end=-1): lower_df = df[df[colname] < value][colname] upper_df = df[df[colname] > value][colname] - lowerneighbour_ind = lower_df.idxmax() - upperneighbour_ind = upper_df.idxmin() + + if not lower_df.empty: + lowerneighbour_ind = lower_df.idxmax() + else: + lowerneighbour_ind = np.nan + + if not upper_df.empty: + upperneighbour_ind = upper_df.idxmin() + else: + upperneighbour_ind = np.nan return [lowerneighbour_ind, upperneighbour_ind] \ No newline at end of file