Skip to content

Commit

Permalink
groupby, resample: Deprecate some positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Jul 11, 2024
1 parent c94d9c2 commit 761177b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]

Check failure on line 2422 in xarray/tests/test_groupby.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9 bare-minimum

TestDatasetResample.test_resample_old_api ValueError: the first argument to .resample must be a dictionary

with pytest.raises(TypeError, match=r"resample\(\) no longer supports"):
ds.resample("1D", dim="time", how="mean") # type: ignore[arg-type]
Expand Down

0 comments on commit 761177b

Please sign in to comment.