From d8666ad801bae8fe01e48708189ec7ca7174e949 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Tue, 23 Mar 2021 09:24:45 +0100 Subject: [PATCH 1/3] Add more scipy interpolations methods --- xarray/core/missing.py | 3 +++ xarray/tests/test_missing.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index e6dd8b537a0..d20ba6855dd 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -460,6 +460,9 @@ def _get_interpolator(method, vectorizeable_only=False, **kwargs): "quadratic", "cubic", "polynomial", + "nearest-up", + "previous", + "next", ] valid_methods = interp1d_methods + [ "barycentric", diff --git a/xarray/tests/test_missing.py b/xarray/tests/test_missing.py index 2ab3508b667..fd3896d9ae8 100644 --- a/xarray/tests/test_missing.py +++ b/xarray/tests/test_missing.py @@ -92,7 +92,17 @@ def make_interpolate_example_data(shape, frac_nan, seed=12345, non_uniform=False def test_interpolate_pd_compat(): shapes = [(8, 8), (1, 20), (20, 1), (100, 100)] frac_nans = [0, 0.5, 1] - methods = ["linear", "nearest", "zero", "slinear", "quadratic", "cubic"] + methods = [ + "linear", + "nearest", + "nearest-up", + "zero", + "slinear", + "quadratic", + "cubic", + "next", + "previous", + ] for (shape, frac_nan, method) in itertools.product(shapes, frac_nans, methods): From a68de97cf9bfb406f8c6c51ab2ff57e304d0583b Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Tue, 23 Mar 2021 10:36:02 +0100 Subject: [PATCH 2/3] comment out pandas test for now --- xarray/core/missing.py | 4 ++-- xarray/tests/test_missing.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index d20ba6855dd..9788040c239 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -598,8 +598,8 @@ def interp(var, indexes_coords, method, **kwargs): Original coordinates should be sorted in strictly ascending order. Note that all the coordinates should be Variable objects. method : string - One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic', - 'cubic'}. For multidimensional interpolation, only + One of {'linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', + 'cubic', 'previous', 'next'}. For multidimensional interpolation, only {'linear', 'nearest'} can be used. **kwargs keyword arguments to be passed to scipy.interpolate diff --git a/xarray/tests/test_missing.py b/xarray/tests/test_missing.py index fd3896d9ae8..4eade6cdbf8 100644 --- a/xarray/tests/test_missing.py +++ b/xarray/tests/test_missing.py @@ -95,13 +95,13 @@ def test_interpolate_pd_compat(): methods = [ "linear", "nearest", - "nearest-up", + # "nearest-up", "zero", "slinear", "quadratic", "cubic", - "next", - "previous", + # "next", + # "previous", ] for (shape, frac_nan, method) in itertools.product(shapes, frac_nans, methods): @@ -301,7 +301,17 @@ def test_interpolate_limits(): @requires_scipy def test_interpolate_methods(): - for method in ["linear", "nearest", "zero", "slinear", "quadratic", "cubic"]: + for method in [ + "linear", + "nearest", + "zero", + "slinear", + "quadratic", + "cubic", + "nearest-up", + "previous", + "next", + ]: kwargs = {} da = xr.DataArray( np.array([0, 1, 2, np.nan, np.nan, np.nan, 6, 7, 8], dtype=np.float64), From 759dfd30aa5f698f628b176d0a5462fbd16c8b30 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Tue, 23 Mar 2021 10:58:52 +0100 Subject: [PATCH 3/3] restrict to next and previous --- xarray/core/missing.py | 3 +-- xarray/tests/test_missing.py | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index 9788040c239..ac0cbe1e702 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -460,7 +460,6 @@ def _get_interpolator(method, vectorizeable_only=False, **kwargs): "quadratic", "cubic", "polynomial", - "nearest-up", "previous", "next", ] @@ -598,7 +597,7 @@ def interp(var, indexes_coords, method, **kwargs): Original coordinates should be sorted in strictly ascending order. Note that all the coordinates should be Variable objects. method : string - One of {'linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', + One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', 'next'}. For multidimensional interpolation, only {'linear', 'nearest'} can be used. **kwargs diff --git a/xarray/tests/test_missing.py b/xarray/tests/test_missing.py index 4eade6cdbf8..71c1fb0e5ad 100644 --- a/xarray/tests/test_missing.py +++ b/xarray/tests/test_missing.py @@ -95,7 +95,6 @@ def test_interpolate_pd_compat(): methods = [ "linear", "nearest", - # "nearest-up", "zero", "slinear", "quadratic", @@ -308,7 +307,6 @@ def test_interpolate_methods(): "slinear", "quadratic", "cubic", - "nearest-up", "previous", "next", ]: