diff --git a/xarray/core/missing.py b/xarray/core/missing.py index e6dd8b537a0..ac0cbe1e702 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -460,6 +460,8 @@ def _get_interpolator(method, vectorizeable_only=False, **kwargs): "quadratic", "cubic", "polynomial", + "previous", + "next", ] valid_methods = interp1d_methods + [ "barycentric", @@ -596,7 +598,7 @@ def interp(var, indexes_coords, method, **kwargs): Note that all the coordinates should be Variable objects. method : string One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic', - 'cubic'}. For multidimensional interpolation, only + '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 2ab3508b667..71c1fb0e5ad 100644 --- a/xarray/tests/test_missing.py +++ b/xarray/tests/test_missing.py @@ -92,7 +92,16 @@ 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", + "zero", + "slinear", + "quadratic", + "cubic", + # "next", + # "previous", + ] for (shape, frac_nan, method) in itertools.product(shapes, frac_nans, methods): @@ -291,7 +300,16 @@ 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", + "previous", + "next", + ]: kwargs = {} da = xr.DataArray( np.array([0, 1, 2, np.nan, np.nan, np.nan, 6, 7, 8], dtype=np.float64),