Skip to content

Commit

Permalink
Remove deprecated behavior for non-dim positional args (pydata#9864)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
max-sixty and pre-commit-ci[bot] authored Dec 9, 2024
1 parent 2d628b6 commit 96e0ff7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 39 deletions.
11 changes: 8 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ What's New
np.random.seed(123456)
.. _whats-new.2024.11.1:
.. _whats-new.2024.12.0:

v.2024.11.1 (unreleased)
v.2024.12.0 (unreleased)
------------------------

New Features
Expand All @@ -28,7 +28,12 @@ New Features

Breaking changes
~~~~~~~~~~~~~~~~

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

Deprecations
~~~~~~~~~~~~
Expand Down
15 changes: 0 additions & 15 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@ def reset_coords(
drop: Literal[True],
) -> Self: ...

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

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

@_deprecate_positional_args("v2023.10.0")
def broadcast_like(
self,
other: T_DataArrayOrSet,
Expand Down Expand Up @@ -1948,7 +1945,6 @@ def _reindex_callback(

return da

@_deprecate_positional_args("v2023.10.0")
def reindex_like(
self,
other: T_DataArrayOrSet,
Expand Down Expand Up @@ -2135,7 +2131,6 @@ def reindex_like(
fill_value=fill_value,
)

@_deprecate_positional_args("v2023.10.0")
def reindex(
self,
indexers: Mapping[Any, Any] | None = None,
Expand Down Expand Up @@ -2960,7 +2955,6 @@ def stack(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def unstack(
self,
dim: Dims = None,
Expand Down Expand Up @@ -3385,7 +3379,6 @@ def drop_isel(
dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs)
return self._from_temp_dataset(dataset)

@_deprecate_positional_args("v2023.10.0")
def dropna(
self,
dim: Hashable,
Expand Down Expand Up @@ -4889,7 +4882,6 @@ def _title_for_slice(self, truncate: int = 50) -> str:

return title

@_deprecate_positional_args("v2023.10.0")
def diff(
self,
dim: Hashable,
Expand Down Expand Up @@ -5198,7 +5190,6 @@ def sortby(
ds = self._to_temp_dataset().sortby(variables, ascending=ascending)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down Expand Up @@ -5318,7 +5309,6 @@ def quantile(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def rank(
self,
dim: Hashable,
Expand Down Expand Up @@ -5897,7 +5887,6 @@ def pad(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def idxmin(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -5995,7 +5984,6 @@ def idxmin(
keep_attrs=keep_attrs,
)

@_deprecate_positional_args("v2023.10.0")
def idxmax(
self,
dim: Hashable = None,
Expand Down Expand Up @@ -6093,7 +6081,6 @@ def idxmax(
keep_attrs=keep_attrs,
)

@_deprecate_positional_args("v2023.10.0")
def argmin(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6195,7 +6182,6 @@ def argmin(
else:
return self._replace_maybe_drop_dims(result)

@_deprecate_positional_args("v2023.10.0")
def argmax(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6544,7 +6530,6 @@ def curvefit(
kwargs=kwargs,
)

@_deprecate_positional_args("v2023.10.0")
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable],
Expand Down
17 changes: 5 additions & 12 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,9 +3276,11 @@ def _shuffle(self, dim, *, indices: GroupIndices, chunks: T_Chunks) -> Self:
subset = self[[name for name in self._variables if name not in is_chunked]]

no_slices: list[list[int]] = [
list(range(*idx.indices(self.sizes[dim])))
if isinstance(idx, slice)
else idx
(
list(range(*idx.indices(self.sizes[dim])))
if isinstance(idx, slice)
else idx
)
for idx in indices
]
no_slices = [idx for idx in no_slices if idx]
Expand Down Expand Up @@ -5102,7 +5104,6 @@ def set_index(
variables, coord_names=coord_names, indexes=indexes_
)

@_deprecate_positional_args("v2023.10.0")
def reset_index(
self,
dims_or_levels: Hashable | Sequence[Hashable],
Expand Down Expand Up @@ -5740,7 +5741,6 @@ def _unstack_full_reindex(
variables, coord_names=coord_names, indexes=indexes
)

@_deprecate_positional_args("v2023.10.0")
def unstack(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6502,7 +6502,6 @@ def transpose(
ds._variables[name] = var.transpose(*var_dims)
return ds

@_deprecate_positional_args("v2023.10.0")
def dropna(
self,
dim: Hashable,
Expand Down Expand Up @@ -7976,7 +7975,6 @@ def _copy_attrs_from(self, other):
if v in self.variables:
self.variables[v].attrs = other.variables[v].attrs

@_deprecate_positional_args("v2023.10.0")
def diff(
self,
dim: Hashable,
Expand Down Expand Up @@ -8324,7 +8322,6 @@ def sortby(
indices[key] = order if ascending else order[::-1]
return aligned_self.isel(indices)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down Expand Up @@ -8505,7 +8502,6 @@ def quantile(
)
return new.assign_coords(quantile=q)

@_deprecate_positional_args("v2023.10.0")
def rank(
self,
dim: Hashable,
Expand Down Expand Up @@ -9476,7 +9472,6 @@ def pad(
attrs = self._attrs if keep_attrs else None
return self._replace_with_new_dims(variables, indexes=indexes, attrs=attrs)

@_deprecate_positional_args("v2023.10.0")
def idxmin(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -9575,7 +9570,6 @@ def idxmin(
)
)

@_deprecate_positional_args("v2023.10.0")
def idxmax(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -10258,7 +10252,6 @@ def _wrapper(Y, *args, **kwargs):

return result

@_deprecate_positional_args("v2023.10.0")
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable],
Expand Down
2 changes: 0 additions & 2 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from xarray.core.variable import IndexVariable, Variable
from xarray.namedarray.pycompat import is_chunked_array
from xarray.util.deprecation_helpers import _deprecate_positional_args

if TYPE_CHECKING:
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -1183,7 +1182,6 @@ def fillna(self, value: Any) -> T_Xarray:
"""
return ops.fillna(self, value)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down
7 changes: 0 additions & 7 deletions xarray/core/weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from xarray.core.computation import apply_ufunc, dot
from xarray.core.types import Dims, T_DataArray, T_Xarray
from xarray.namedarray.utils import is_duck_dask_array
from xarray.util.deprecation_helpers import _deprecate_positional_args

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

@_deprecate_positional_args("v2023.10.0")
def sum_of_weights(
self,
dim: Dims = None,
Expand All @@ -465,7 +463,6 @@ def sum_of_weights(
self._sum_of_weights, dim=dim, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def sum_of_squares(
self,
dim: Dims = None,
Expand All @@ -477,7 +474,6 @@ def sum_of_squares(
self._sum_of_squares, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def sum(
self,
dim: Dims = None,
Expand All @@ -489,7 +485,6 @@ def sum(
self._weighted_sum, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def mean(
self,
dim: Dims = None,
Expand All @@ -501,7 +496,6 @@ def mean(
self._weighted_mean, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def var(
self,
dim: Dims = None,
Expand All @@ -513,7 +507,6 @@ def var(
self._weighted_var, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def std(
self,
dim: Dims = None,
Expand Down

0 comments on commit 96e0ff7

Please sign in to comment.