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 18, 2024
1 parent b55c783 commit a797d2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
5 changes: 5 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6694,11 +6694,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 @@ -6815,6 +6817,7 @@ def groupby(
restore_coord_dims=restore_coord_dims,
)

@_deprecate_positional_args("v2024.08.0")
def groupby_bins(
self,
group: Hashable | DataArray | IndexVariable,
Expand Down Expand Up @@ -7239,9 +7242,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
5 changes: 5 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10263,11 +10263,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 @@ -10351,6 +10353,7 @@ def groupby(
restore_coord_dims=restore_coord_dims,
)

@_deprecate_positional_args("v2024.08.0")
def groupby_bins(
self,
group: Hashable | DataArray | IndexVariable,
Expand Down Expand Up @@ -10620,9 +10623,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
21 changes: 1 addition & 20 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 @@ -2408,25 +2408,6 @@ def test_resample_drop_nondim_coords(self) -> None:
actual = ds.resample(time="1h").interpolate("linear")
assert "tc" not in actual.coords

def test_resample_old_api(self) -> None:
times = pd.date_range("2000-01-01", freq="6h", periods=10)
ds = Dataset(
{
"foo": (["time", "x", "y"], np.random.randn(10, 5, 3)),
"bar": ("time", np.random.randn(10), {"meta": "data"}),
"time": times,
}
)

with pytest.raises(TypeError, match=r"resample\(\) no longer supports"):
ds.resample("1D", "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]

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

def test_resample_ds_da_are_the_same(self) -> None:
time = pd.date_range("2000-01-01", freq="6h", periods=365 * 4)
ds = xr.Dataset(
Expand Down

0 comments on commit a797d2b

Please sign in to comment.