Skip to content

Commit

Permalink
Remove keep_attrs from resample signature (pydata#8444)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Nov 12, 2023
1 parent e5d163a commit 8e95b60
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 22 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Deprecations
existing methods work and don't raise any warnings, given the relatively small
benefits of the change.
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Finally remove ``keep_attrs`` kwarg from :py:meth:`DataArray.resample` and
:py:meth:`Dataset.resample`. These were deprecated a long time ago.
By `Deepak Cherian <https://github.com/dcherian>`_.

Bug fixes
~~~~~~~~~
Expand Down
8 changes: 0 additions & 8 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ def _resample(
base: int | None,
offset: pd.Timedelta | datetime.timedelta | str | None,
origin: str | DatetimeLike,
keep_attrs: bool | None,
loffset: datetime.timedelta | str | None,
restore_coord_dims: bool | None,
**indexer_kwargs: str,
Expand Down Expand Up @@ -989,13 +988,6 @@ def _resample(
from xarray.core.pdcompat import _convert_base_to_offset
from xarray.core.resample import RESAMPLE_DIM

if keep_attrs is not None:
warnings.warn(
"Passing ``keep_attrs`` to ``resample`` has no effect and will raise an"
" error in xarray 0.20. Pass ``keep_attrs`` directly to the applied"
" function, e.g. ``resample(...).mean(keep_attrs=True)``."
)

# note: the second argument (now 'skipna') use to be 'dim'
if (
(skipna is not None and not isinstance(skipna, bool))
Expand Down
2 changes: 0 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7021,7 +7021,6 @@ def resample(
base: int | None = None,
offset: pd.Timedelta | datetime.timedelta | str | None = None,
origin: str | DatetimeLike = "start_day",
keep_attrs: bool | None = None,
loffset: datetime.timedelta | str | None = None,
restore_coord_dims: bool | None = None,
**indexer_kwargs: str,
Expand Down Expand Up @@ -7143,7 +7142,6 @@ def resample(
base=base,
offset=offset,
origin=origin,
keep_attrs=keep_attrs,
loffset=loffset,
restore_coord_dims=restore_coord_dims,
**indexer_kwargs,
Expand Down
2 changes: 0 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10327,7 +10327,6 @@ def resample(
base: int | None = None,
offset: pd.Timedelta | datetime.timedelta | str | None = None,
origin: str | DatetimeLike = "start_day",
keep_attrs: bool | None = None,
loffset: datetime.timedelta | str | None = None,
restore_coord_dims: bool | None = None,
**indexer_kwargs: str,
Expand Down Expand Up @@ -10404,7 +10403,6 @@ def resample(
base=base,
offset=offset,
origin=origin,
keep_attrs=keep_attrs,
loffset=loffset,
restore_coord_dims=restore_coord_dims,
**indexer_kwargs,
Expand Down
10 changes: 0 additions & 10 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,11 +1776,6 @@ def test_resample_keep_attrs(self):
expected = DataArray([1, 1, 1], [("time", times[::4])], attrs=array.attrs)
assert_identical(result, expected)

with pytest.warns(
UserWarning, match="Passing ``keep_attrs`` to ``resample`` has no effect."
):
array.resample(time="1D", keep_attrs=True)

def test_resample_skipna(self):
times = pd.date_range("2000-01-01", freq="6H", periods=10)
array = DataArray(np.ones(10), [("time", times)])
Expand Down Expand Up @@ -2138,11 +2133,6 @@ def test_resample_by_mean_with_keep_attrs(self):
expected = ds.attrs
assert expected == actual

with pytest.warns(
UserWarning, match="Passing ``keep_attrs`` to ``resample`` has no effect."
):
ds.resample(time="1D", keep_attrs=True)

def test_resample_loffset(self):
times = pd.date_range("2000-01-01", freq="6H", periods=10)
ds = Dataset(
Expand Down

0 comments on commit 8e95b60

Please sign in to comment.