Skip to content

Commit 96e0ff7

Browse files
Remove deprecated behavior for non-dim positional args (#9864)
* Remove deprecated behavior with for non-dim positional args * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2d628b6 commit 96e0ff7

File tree

5 files changed

+13
-39
lines changed

5 files changed

+13
-39
lines changed

doc/whats-new.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ What's New
1414
1515
np.random.seed(123456)
1616
17-
.. _whats-new.2024.11.1:
17+
.. _whats-new.2024.12.0:
1818

19-
v.2024.11.1 (unreleased)
19+
v.2024.12.0 (unreleased)
2020
------------------------
2121

2222
New Features
@@ -28,7 +28,12 @@ New Features
2828

2929
Breaking changes
3030
~~~~~~~~~~~~~~~~
31-
31+
- Methods including ``dropna``, ``rank``, ``idxmax``, ``idxmin`` require
32+
non-dimension arguments to be passed as keyword arguments. The previous
33+
behavior, which allowed ``.idxmax('foo', 'all')`` was too easily confused with
34+
``'all'`` being a dimension. The updated equivalent is ``.idxmax('foo',
35+
how='all')``. The previous behavior was deprecated in v2023.10.0.
36+
By `Maximilian Roos <https://github.com/max-sixty>`_.
3237

3338
Deprecations
3439
~~~~~~~~~~~~

xarray/core/dataarray.py

-15
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ def reset_coords(
10261026
drop: Literal[True],
10271027
) -> Self: ...
10281028

1029-
@_deprecate_positional_args("v2023.10.0")
10301029
def reset_coords(
10311030
self,
10321031
names: Dims = None,
@@ -1364,7 +1363,6 @@ def chunksizes(self) -> Mapping[Any, tuple[int, ...]]:
13641363
all_variables = [self.variable] + [c.variable for c in self.coords.values()]
13651364
return get_chunksizes(all_variables)
13661365

1367-
@_deprecate_positional_args("v2023.10.0")
13681366
def chunk(
13691367
self,
13701368
chunks: T_ChunksFreq = {}, # noqa: B006 # {} even though it's technically unsafe, is being used intentionally here (#4667)
@@ -1835,7 +1833,6 @@ def thin(
18351833
ds = self._to_temp_dataset().thin(indexers, **indexers_kwargs)
18361834
return self._from_temp_dataset(ds)
18371835

1838-
@_deprecate_positional_args("v2023.10.0")
18391836
def broadcast_like(
18401837
self,
18411838
other: T_DataArrayOrSet,
@@ -1948,7 +1945,6 @@ def _reindex_callback(
19481945

19491946
return da
19501947

1951-
@_deprecate_positional_args("v2023.10.0")
19521948
def reindex_like(
19531949
self,
19541950
other: T_DataArrayOrSet,
@@ -2135,7 +2131,6 @@ def reindex_like(
21352131
fill_value=fill_value,
21362132
)
21372133

2138-
@_deprecate_positional_args("v2023.10.0")
21392134
def reindex(
21402135
self,
21412136
indexers: Mapping[Any, Any] | None = None,
@@ -2960,7 +2955,6 @@ def stack(
29602955
)
29612956
return self._from_temp_dataset(ds)
29622957

2963-
@_deprecate_positional_args("v2023.10.0")
29642958
def unstack(
29652959
self,
29662960
dim: Dims = None,
@@ -3385,7 +3379,6 @@ def drop_isel(
33853379
dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs)
33863380
return self._from_temp_dataset(dataset)
33873381

3388-
@_deprecate_positional_args("v2023.10.0")
33893382
def dropna(
33903383
self,
33913384
dim: Hashable,
@@ -4889,7 +4882,6 @@ def _title_for_slice(self, truncate: int = 50) -> str:
48894882

48904883
return title
48914884

4892-
@_deprecate_positional_args("v2023.10.0")
48934885
def diff(
48944886
self,
48954887
dim: Hashable,
@@ -5198,7 +5190,6 @@ def sortby(
51985190
ds = self._to_temp_dataset().sortby(variables, ascending=ascending)
51995191
return self._from_temp_dataset(ds)
52005192

5201-
@_deprecate_positional_args("v2023.10.0")
52025193
def quantile(
52035194
self,
52045195
q: ArrayLike,
@@ -5318,7 +5309,6 @@ def quantile(
53185309
)
53195310
return self._from_temp_dataset(ds)
53205311

5321-
@_deprecate_positional_args("v2023.10.0")
53225312
def rank(
53235313
self,
53245314
dim: Hashable,
@@ -5897,7 +5887,6 @@ def pad(
58975887
)
58985888
return self._from_temp_dataset(ds)
58995889

5900-
@_deprecate_positional_args("v2023.10.0")
59015890
def idxmin(
59025891
self,
59035892
dim: Hashable | None = None,
@@ -5995,7 +5984,6 @@ def idxmin(
59955984
keep_attrs=keep_attrs,
59965985
)
59975986

5998-
@_deprecate_positional_args("v2023.10.0")
59995987
def idxmax(
60005988
self,
60015989
dim: Hashable = None,
@@ -6093,7 +6081,6 @@ def idxmax(
60936081
keep_attrs=keep_attrs,
60946082
)
60956083

6096-
@_deprecate_positional_args("v2023.10.0")
60976084
def argmin(
60986085
self,
60996086
dim: Dims = None,
@@ -6195,7 +6182,6 @@ def argmin(
61956182
else:
61966183
return self._replace_maybe_drop_dims(result)
61976184

6198-
@_deprecate_positional_args("v2023.10.0")
61996185
def argmax(
62006186
self,
62016187
dim: Dims = None,
@@ -6544,7 +6530,6 @@ def curvefit(
65446530
kwargs=kwargs,
65456531
)
65466532

6547-
@_deprecate_positional_args("v2023.10.0")
65486533
def drop_duplicates(
65496534
self,
65506535
dim: Hashable | Iterable[Hashable],

xarray/core/dataset.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3276,9 +3276,11 @@ def _shuffle(self, dim, *, indices: GroupIndices, chunks: T_Chunks) -> Self:
32763276
subset = self[[name for name in self._variables if name not in is_chunked]]
32773277

32783278
no_slices: list[list[int]] = [
3279-
list(range(*idx.indices(self.sizes[dim])))
3280-
if isinstance(idx, slice)
3281-
else idx
3279+
(
3280+
list(range(*idx.indices(self.sizes[dim])))
3281+
if isinstance(idx, slice)
3282+
else idx
3283+
)
32823284
for idx in indices
32833285
]
32843286
no_slices = [idx for idx in no_slices if idx]
@@ -5102,7 +5104,6 @@ def set_index(
51025104
variables, coord_names=coord_names, indexes=indexes_
51035105
)
51045106

5105-
@_deprecate_positional_args("v2023.10.0")
51065107
def reset_index(
51075108
self,
51085109
dims_or_levels: Hashable | Sequence[Hashable],
@@ -5740,7 +5741,6 @@ def _unstack_full_reindex(
57405741
variables, coord_names=coord_names, indexes=indexes
57415742
)
57425743

5743-
@_deprecate_positional_args("v2023.10.0")
57445744
def unstack(
57455745
self,
57465746
dim: Dims = None,
@@ -6502,7 +6502,6 @@ def transpose(
65026502
ds._variables[name] = var.transpose(*var_dims)
65036503
return ds
65046504

6505-
@_deprecate_positional_args("v2023.10.0")
65066505
def dropna(
65076506
self,
65086507
dim: Hashable,
@@ -7976,7 +7975,6 @@ def _copy_attrs_from(self, other):
79767975
if v in self.variables:
79777976
self.variables[v].attrs = other.variables[v].attrs
79787977

7979-
@_deprecate_positional_args("v2023.10.0")
79807978
def diff(
79817979
self,
79827980
dim: Hashable,
@@ -8324,7 +8322,6 @@ def sortby(
83248322
indices[key] = order if ascending else order[::-1]
83258323
return aligned_self.isel(indices)
83268324

8327-
@_deprecate_positional_args("v2023.10.0")
83288325
def quantile(
83298326
self,
83308327
q: ArrayLike,
@@ -8505,7 +8502,6 @@ def quantile(
85058502
)
85068503
return new.assign_coords(quantile=q)
85078504

8508-
@_deprecate_positional_args("v2023.10.0")
85098505
def rank(
85108506
self,
85118507
dim: Hashable,
@@ -9476,7 +9472,6 @@ def pad(
94769472
attrs = self._attrs if keep_attrs else None
94779473
return self._replace_with_new_dims(variables, indexes=indexes, attrs=attrs)
94789474

9479-
@_deprecate_positional_args("v2023.10.0")
94809475
def idxmin(
94819476
self,
94829477
dim: Hashable | None = None,
@@ -9575,7 +9570,6 @@ def idxmin(
95759570
)
95769571
)
95779572

9578-
@_deprecate_positional_args("v2023.10.0")
95799573
def idxmax(
95809574
self,
95819575
dim: Hashable | None = None,
@@ -10258,7 +10252,6 @@ def _wrapper(Y, *args, **kwargs):
1025810252

1025910253
return result
1026010254

10261-
@_deprecate_positional_args("v2023.10.0")
1026210255
def drop_duplicates(
1026310256
self,
1026410257
dim: Hashable | Iterable[Hashable],

xarray/core/groupby.py

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
)
5151
from xarray.core.variable import IndexVariable, Variable
5252
from xarray.namedarray.pycompat import is_chunked_array
53-
from xarray.util.deprecation_helpers import _deprecate_positional_args
5453

5554
if TYPE_CHECKING:
5655
from numpy.typing import ArrayLike
@@ -1183,7 +1182,6 @@ def fillna(self, value: Any) -> T_Xarray:
11831182
"""
11841183
return ops.fillna(self, value)
11851184

1186-
@_deprecate_positional_args("v2023.10.0")
11871185
def quantile(
11881186
self,
11891187
q: ArrayLike,

xarray/core/weighted.py

-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from xarray.core.computation import apply_ufunc, dot
1212
from xarray.core.types import Dims, T_DataArray, T_Xarray
1313
from xarray.namedarray.utils import is_duck_dask_array
14-
from xarray.util.deprecation_helpers import _deprecate_positional_args
1514

1615
# Weighted quantile methods are a subset of the numpy supported quantile methods.
1716
QUANTILE_METHODS = Literal[
@@ -454,7 +453,6 @@ def _weighted_quantile_1d(
454453
def _implementation(self, func, dim, **kwargs):
455454
raise NotImplementedError("Use `Dataset.weighted` or `DataArray.weighted`")
456455

457-
@_deprecate_positional_args("v2023.10.0")
458456
def sum_of_weights(
459457
self,
460458
dim: Dims = None,
@@ -465,7 +463,6 @@ def sum_of_weights(
465463
self._sum_of_weights, dim=dim, keep_attrs=keep_attrs
466464
)
467465

468-
@_deprecate_positional_args("v2023.10.0")
469466
def sum_of_squares(
470467
self,
471468
dim: Dims = None,
@@ -477,7 +474,6 @@ def sum_of_squares(
477474
self._sum_of_squares, dim=dim, skipna=skipna, keep_attrs=keep_attrs
478475
)
479476

480-
@_deprecate_positional_args("v2023.10.0")
481477
def sum(
482478
self,
483479
dim: Dims = None,
@@ -489,7 +485,6 @@ def sum(
489485
self._weighted_sum, dim=dim, skipna=skipna, keep_attrs=keep_attrs
490486
)
491487

492-
@_deprecate_positional_args("v2023.10.0")
493488
def mean(
494489
self,
495490
dim: Dims = None,
@@ -501,7 +496,6 @@ def mean(
501496
self._weighted_mean, dim=dim, skipna=skipna, keep_attrs=keep_attrs
502497
)
503498

504-
@_deprecate_positional_args("v2023.10.0")
505499
def var(
506500
self,
507501
dim: Dims = None,
@@ -513,7 +507,6 @@ def var(
513507
self._weighted_var, dim=dim, skipna=skipna, keep_attrs=keep_attrs
514508
)
515509

516-
@_deprecate_positional_args("v2023.10.0")
517510
def std(
518511
self,
519512
dim: Dims = None,

0 commit comments

Comments
 (0)