Skip to content

Commit 047ee75

Browse files
committed
remove reduce arg
1 parent 60f5afb commit 047ee75

File tree

3 files changed

+32
-71
lines changed

3 files changed

+32
-71
lines changed

xarray/core/dataarray.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,20 +2217,15 @@ def interp(
22172217
coords: Mapping[Any, Any] | None = None,
22182218
method: InterpOptions = "linear",
22192219
assume_sorted: bool = False,
2220-
reduce: bool = True,
22212220
kwargs: Mapping[str, Any] | None = None,
22222221
**coords_kwargs: Any,
22232222
) -> Self:
22242223
"""
22252224
Interpolate a DataArray onto new coordinates.
22262225
22272226
Performs univariate or multivariate interpolation of a Dataset onto new coordinates,
2228-
utilizing either NumPy or SciPy interpolation routines.
2229-
2230-
When interpolating along multiple dimensions, the process attempts to decompose the
2231-
interpolation into independent interpolations along one dimension at a time, unless
2232-
`reduce=False` is passed. The specific interpolation method and dimensionality
2233-
determine which interpolant is used:
2227+
utilizing either NumPy or SciPy interpolation routines. The specific interpolation
2228+
method and dimensionality determine which interpolant is used:
22342229
22352230
1. **Interpolation along one dimension of 1D data (`method='linear'`)**
22362231
- Uses :py:class:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
@@ -2269,10 +2264,6 @@ def interp(
22692264
If False, values of x can be in any order and they are sorted
22702265
first. If True, x has to be an array of monotonically increasing
22712266
values.
2272-
reduce : bool, default: True
2273-
If True, the interpolation is decomposed into independent interpolations along one dimension at a time,
2274-
where the interpolation coordinates are independent. Setting this to be True alters the behavior of certain
2275-
multi-dimensional interpolants compared to the default SciPy output.
22762267
kwargs : dict-like or None, default: None
22772268
Additional keyword arguments passed to scipy's interpolator. Valid
22782269
options and their behavior depend whether ``interp1d`` or
@@ -2289,8 +2280,9 @@ def interp(
22892280
Notes
22902281
-----
22912282
- SciPy is required for certain interpolation methods.
2292-
- Allowing `reduce=True` (the default) may alter the behavior of interpolation along multiple dimensions
2293-
compared to the default behavior in SciPy.
2283+
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
2284+
the process attempts to decompose the interpolation into independent interpolations
2285+
along one dimension at a time.
22942286
22952287
See Also
22962288
--------
@@ -2377,7 +2369,6 @@ def interp(
23772369
method=method,
23782370
kwargs=kwargs,
23792371
assume_sorted=assume_sorted,
2380-
reduce=reduce,
23812372
**coords_kwargs,
23822373
)
23832374
return self._from_temp_dataset(ds)
@@ -2387,16 +2378,13 @@ def interp_like(
23872378
other: T_Xarray,
23882379
method: InterpOptions = "linear",
23892380
assume_sorted: bool = False,
2390-
reduce: bool = True,
23912381
kwargs: Mapping[str, Any] | None = None,
23922382
) -> Self:
23932383
"""Interpolate this object onto the coordinates of another object,
23942384
filling out of range values with NaN.
23952385
2396-
When interpolating along multiple dimensions, the process attempts to decompose the
2397-
interpolation into independent interpolations along one dimension at a time, unless
2398-
`reduce=False` is passed. The specific interpolation method and dimensionality
2399-
determine which interpolant is used:
2386+
The specific interpolation method and dimensionality determine which
2387+
interpolant is used:
24002388
24012389
1. **Interpolation along one dimension of 1D data (`method='linear'`)**
24022390
- Uses :py:class:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
@@ -2432,10 +2420,6 @@ def interp_like(
24322420
in any order and they are sorted first. If True, interpolated
24332421
coordinates are assumed to be an array of monotonically increasing
24342422
values.
2435-
reduce : bool, default: True
2436-
If True, the interpolation is decomposed into independent interpolations along one dimension at a time,
2437-
where the interpolation coordinates are independent. Setting this to be True alters the behavior of certain
2438-
multi-dimensional interpolants compared to the default SciPy output.
24392423
kwargs : dict, optional
24402424
Additional keyword arguments passed to the interpolant.
24412425
@@ -2447,9 +2431,12 @@ def interp_like(
24472431
24482432
Notes
24492433
-----
2450-
scipy is required.
2451-
If the dataarray has object-type coordinates, reindex is used for these
2452-
coordinates instead of the interpolation.
2434+
- scipy is required.
2435+
- If the dataarray has object-type coordinates, reindex is used for these
2436+
coordinates instead of the interpolation.
2437+
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
2438+
the process attempts to decompose the interpolation into independent interpolations
2439+
along one dimension at a time.
24532440
24542441
See Also
24552442
--------
@@ -2518,11 +2505,7 @@ def interp_like(
25182505
f"interp only works for a numeric type array. Given {self.dtype}."
25192506
)
25202507
ds = self._to_temp_dataset().interp_like(
2521-
other,
2522-
method=method,
2523-
kwargs=kwargs,
2524-
assume_sorted=assume_sorted,
2525-
reduce=reduce,
2508+
other, method=method, kwargs=kwargs, assume_sorted=assume_sorted
25262509
)
25272510
return self._from_temp_dataset(ds)
25282511

xarray/core/dataset.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,7 +3884,6 @@ def interp(
38843884
coords: Mapping[Any, Any] | None = None,
38853885
method: InterpOptions = "linear",
38863886
assume_sorted: bool = False,
3887-
reduce: bool = True,
38883887
kwargs: Mapping[str, Any] | None = None,
38893888
method_non_numeric: str = "nearest",
38903889
**coords_kwargs: Any,
@@ -3893,12 +3892,8 @@ def interp(
38933892
Interpolate a Dataset onto new coordinates.
38943893
38953894
Performs univariate or multivariate interpolation of a Dataset onto new coordinates,
3896-
utilizing either NumPy or SciPy interpolation routines.
3897-
3898-
When interpolating along multiple dimensions, the process attempts to decompose the
3899-
interpolation into independent interpolations along one dimension at a time, unless
3900-
`reduce=False` is passed. The specific interpolation method and dimensionality
3901-
determine which interpolant is used:
3895+
utilizing either NumPy or SciPy interpolation routines. The specific interpolation
3896+
method and dimensionality determine which interpolant is used:
39023897
39033898
1. **Interpolation along one dimension of 1D data (`method='linear'`)**
39043899
- Uses :py:class:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
@@ -3938,10 +3933,6 @@ def interp(
39383933
in any order and they are sorted first. If True, interpolated
39393934
coordinates are assumed to be an array of monotonically increasing
39403935
values.
3941-
reduce : bool, default: True
3942-
If True, the interpolation is decomposed into independent interpolations of minimal dimensionality such that
3943-
the interpolation coordinates are independent. Setting this to be True alters the behavior of certain
3944-
multi-dimensional interpolants compared to the default SciPy output.
39453936
kwargs : dict, optional
39463937
Additional keyword arguments passed to the interpolator. Valid
39473938
options and their behavior depend which interpolant is used.
@@ -3961,10 +3952,9 @@ def interp(
39613952
Notes
39623953
-----
39633954
- SciPy is required for certain interpolation methods.
3964-
- Allowing `reduce=True` (the default) may alter the behavior of interpolation along multiple dimensions
3965-
compared to the default behavior in SciPy.
3966-
3967-
See Also
3955+
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
3956+
the process attempts to decompose the interpolation into independent interpolations
3957+
along one dimension at a time.
39683958
--------
39693959
scipy.interpolate.interp1d
39703960
scipy.interpolate.interpn
@@ -4125,9 +4115,7 @@ def _validate_interp_indexer(x, new_x):
41254115
if dtype_kind in "uifc":
41264116
# For normal number types do the interpolation:
41274117
var_indexers = {k: v for k, v in use_indexers.items() if k in var.dims}
4128-
variables[name] = missing.interp(
4129-
var, var_indexers, method, reduce=reduce, **kwargs
4130-
)
4118+
variables[name] = missing.interp(var, var_indexers, method, **kwargs)
41314119
elif dtype_kind in "ObU" and (use_indexers.keys() & var.dims):
41324120
# For types that we do not understand do stepwise
41334121
# interpolation to avoid modifying the elements.
@@ -4188,19 +4176,14 @@ def interp_like(
41884176
other: T_Xarray,
41894177
method: InterpOptions = "linear",
41904178
assume_sorted: bool = False,
4191-
reduce: bool = True,
41924179
kwargs: Mapping[str, Any] | None = None,
41934180
method_non_numeric: str = "nearest",
41944181
) -> Self:
41954182
"""Interpolate this object onto the coordinates of another object.
41964183
41974184
Performs univariate or multivariate interpolation of a Dataset onto new coordinates,
4198-
utilizing either NumPy or SciPy interpolation routines.
4199-
4200-
When interpolating along multiple dimensions, the process attempts to decompose the
4201-
interpolation into independent interpolations along one dimension at a time, unless
4202-
`reduce=False` is passed. The specific interpolation method and dimensionality
4203-
determine which interpolant is used:
4185+
utilizing either NumPy or SciPy interpolation routines. The specific interpolation
4186+
method and dimensionality determine which interpolant is used:
42044187
42054188
1. **Interpolation along one dimension of 1D data (`method='linear'`)**
42064189
- Uses :py:class:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
@@ -4239,10 +4222,6 @@ def interp_like(
42394222
in any order and they are sorted first. If True, interpolated
42404223
coordinates are assumed to be an array of monotonically increasing
42414224
values.
4242-
reduce : bool, default: True
4243-
If True, the interpolation is decomposed into independent 1-dimensional interpolations such that
4244-
the interpolation coordinates are independent. Setting this to be True alters the behavior of certain
4245-
multi-dimensional interpolants compared to the default SciPy output.
42464225
kwargs : dict, optional
42474226
Additional keyword arguments passed to the interpolator. Valid
42484227
options and their behavior depend which interpolant is use
@@ -4258,9 +4237,12 @@ def interp_like(
42584237
42594238
Notes
42604239
-----
4261-
scipy is required.
4262-
If the dataset has object-type coordinates, reindex is used for these
4263-
coordinates instead of the interpolation.
4240+
- scipy is required.
4241+
- If the dataset has object-type coordinates, reindex is used for these
4242+
coordinates instead of the interpolation.
4243+
- When interpolating along multiple dimensions with methods `linear` and `nearest`,
4244+
the process attempts to decompose the interpolation into independent interpolations
4245+
along one dimension at a time.
42644246
42654247
See Also
42664248
--------

xarray/core/missing.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ def _get_interpolator(
506506
interp_class = _import_interpolant("KroghInterpolator", method)
507507
elif method == "pchip":
508508
kwargs.update(axis=-1)
509+
# pchip default behavior is to extrapolate
509510
kwargs.setdefault("extrapolate", False)
510511
interp_class = _import_interpolant("PchipInterpolator", method)
511512
elif method == "spline":
@@ -601,7 +602,7 @@ def _floatize_x(x, new_x):
601602
return x, new_x
602603

603604

604-
def interp(var, indexes_coords, method: InterpOptions, reduce: bool = True, **kwargs):
605+
def interp(var, indexes_coords, method: InterpOptions, **kwargs):
605606
"""Make an interpolation of Variable
606607
607608
Parameters
@@ -615,10 +616,6 @@ def interp(var, indexes_coords, method: InterpOptions, reduce: bool = True, **kw
615616
One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic',
616617
'cubic'}. For multidimensional interpolation, only
617618
{'linear', 'nearest'} can be used.
618-
reduce:
619-
Decompose the interpolation along independent interpolation dimensions when
620-
possible. This will likely improve performance over true multi-dimensional
621-
interpolation but will alter the result for certain interpolators.
622619
**kwargs
623620
keyword arguments to be passed to scipy.interpolate
624621
@@ -636,9 +633,8 @@ def interp(var, indexes_coords, method: InterpOptions, reduce: bool = True, **kw
636633

637634
result = var
638635

639-
if reduce:
640-
# decompose the interpolation into a succession of independent interpolation. This may
641-
# affect the mathematical behavior of certain nd interpolants.
636+
if method in ["linear", "nearest"]:
637+
# decompose the interpolation into a succession of independent interpolation.
642638
indexes_coords = decompose_interp(indexes_coords)
643639
else:
644640
indexes_coords = [indexes_coords]

0 commit comments

Comments
 (0)