Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groupby, resample: Deprecate some positional args #9236

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading