From 761177b6c76bf8ee7ad6e2041366e275d216b3a1 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 11 Jul 2024 22:32:51 +0530 Subject: [PATCH] groupby, resample: Deprecate some positional args --- xarray/core/dataarray.py | 6 ++++++ xarray/core/dataset.py | 6 ++++++ xarray/tests/test_groupby.py | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index b62189c3aa1..e1a9cb55227 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -6681,11 +6681,13 @@ def interp_calendar( """ return interp_calendar(self, target, dim=dim) + @_deprecate_positional_args("v2024.08.0") def groupby( self, group: ( Hashable | DataArray | IndexVariable | Mapping[Any, Grouper] | None ) = None, + *, squeeze: bool | None = None, restore_coord_dims: bool = False, **groupers: Grouper, @@ -6802,10 +6804,12 @@ def groupby( restore_coord_dims=restore_coord_dims, ) + @_deprecate_positional_args("v2024.08.0") def groupby_bins( self, group: Hashable | DataArray | IndexVariable, bins: ArrayLike, + *, right: bool = True, labels: ArrayLike | Literal[False] | None = None, precision: int = 3, @@ -7226,9 +7230,11 @@ def coarsen( coord_func=coord_func, ) + @_deprecate_positional_args("v2024.08.0") def resample( self, indexer: Mapping[Hashable, str | Resampler] | None = None, + *, skipna: bool | None = None, closed: SideOptions | None = None, label: SideOptions | None = None, diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index e69a3664414..44fff3c617e 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -10255,11 +10255,13 @@ def interp_calendar( """ return interp_calendar(self, target, dim=dim) + @_deprecate_positional_args("v2024.08.0") def groupby( self, group: ( Hashable | DataArray | IndexVariable | Mapping[Any, Grouper] | None ) = None, + *, squeeze: bool | None = None, restore_coord_dims: bool = False, **groupers: Grouper, @@ -10343,10 +10345,12 @@ def groupby( restore_coord_dims=restore_coord_dims, ) + @_deprecate_positional_args("v2024.08.0") def groupby_bins( self, group: Hashable | DataArray | IndexVariable, bins: ArrayLike, + *, right: bool = True, labels: ArrayLike | None = None, precision: int = 3, @@ -10612,9 +10616,11 @@ def coarsen( coord_func=coord_func, ) + @_deprecate_positional_args("v2024.08.0") def resample( self, indexer: Mapping[Any, str | Resampler] | None = None, + *, skipna: bool | None = None, closed: SideOptions | None = None, label: SideOptions | None = None, diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index ea3a71ad65b..271c8d3dabb 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -722,7 +722,7 @@ def test_groupby_reduce_dimension_error(array) -> None: def test_groupby_multiple_string_args(array) -> None: with pytest.raises(TypeError): - array.groupby("x", "y") + array.groupby("x", squeeze="y") def test_groupby_bins_timeseries() -> None: @@ -2419,7 +2419,7 @@ def test_resample_old_api(self) -> None: ) with pytest.raises(TypeError, match=r"resample\(\) no longer supports"): - ds.resample("1D", "time") # type: ignore[arg-type] + ds.resample("1D", squeeze="time") # type: ignore[arg-type] with pytest.raises(TypeError, match=r"resample\(\) no longer supports"): ds.resample("1D", dim="time", how="mean") # type: ignore[arg-type]