From f9fcb4740699136541a867b3fed6d8198fcdac53 Mon Sep 17 00:00:00 2001 From: Zihao Xu Date: Thu, 20 Jun 2024 09:25:10 -0400 Subject: [PATCH] Sort before interpolating (#61) --- rframe/indexes/interpolating_index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rframe/indexes/interpolating_index.py b/rframe/indexes/interpolating_index.py index bfa5a87..f449dd6 100644 --- a/rframe/indexes/interpolating_index.py +++ b/rframe/indexes/interpolating_index.py @@ -23,6 +23,9 @@ def interpolater(x, xs, ys, kind="linear"): @interpolater.register(int) def interpolate_number(x, xs, ys, kind="linear"): if isinstance(ys[0], (float, int)): + sort = np.argsort(xs) + xs = np.array(xs)[sort] + ys = np.array(ys)[sort] return np.interp(x, xs, ys) return nn_interpolate(x, xs, ys)