Skip to content

Commit 1735892

Browse files
authored
rolling keep_attrs & default True (#4510)
* rolling keep_attrs & default True * WIP * remove docstr on keep_attrs * adapt tests * rolling WIP * small update * update docs * update tests * undo refactoring * some more fixes * more doc fixes * test the name is conserved * test global default and kwarg * more fixes... * do a deep copy * Apply suggestions from code review
1 parent 7ce0110 commit 1735892

File tree

5 files changed

+326
-89
lines changed

5 files changed

+326
-89
lines changed

doc/whats-new.rst

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ v0.16.2 (unreleased)
2323
Breaking changes
2424
~~~~~~~~~~~~~~~~
2525

26+
- :py:attr:`DataArray.rolling` and :py:attr:`Dataset.rolling` no longer support passing ``keep_attrs``
27+
via its constructor. Pass ``keep_attrs`` via the applied function, i.e. use
28+
``ds.rolling(...).mean(keep_attrs=False)`` instead of ``ds.rolling(..., keep_attrs=False).mean()``
29+
Rolling operations now keep their attributes per default (:pull:`4510`).
30+
By `Mathias Hauser <https://github.com/mathause>`_.
2631

2732
New Features
2833
~~~~~~~~~~~~
@@ -64,6 +69,9 @@ Bug fixes
6469
By `Mathias Hauser <https://github.com/mathause>`_.
6570
- :py:func:`combine_by_coords` now raises an informative error when passing coordinates
6671
with differing calendars (:issue:`4495`). By `Mathias Hauser <https://github.com/mathause>`_.
72+
- :py:attr:`DataArray.rolling` and :py:attr:`Dataset.rolling` now also keep the attributes and names of of (wrapped)
73+
``DataArray`` objects, previously only the global attributes were retained (:issue:`4497`, :pull:`4510`).
74+
By `Mathias Hauser <https://github.com/mathause>`_.
6775
- Improve performance where reading small slices from huge dimensions was slower than necessary (:pull:`4560`). By `Dion Häfner <https://github.com/dionhaefner>`_.
6876

6977
Documentation

xarray/core/common.py

-6
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,6 @@ def rolling(
811811
setting min_periods equal to the size of the window.
812812
center : bool or mapping, default: False
813813
Set the labels at the center of the window.
814-
keep_attrs : bool, optional
815-
If True, the object's attributes (`attrs`) will be copied from
816-
the original object to the new one. If False (default), the new
817-
object will be returned without attributes.
818814
**window_kwargs : optional
819815
The keyword arguments form of ``dim``.
820816
One of dim or window_kwargs must be provided.
@@ -863,8 +859,6 @@ def rolling(
863859
core.rolling.DataArrayRolling
864860
core.rolling.DatasetRolling
865861
"""
866-
if keep_attrs is None:
867-
keep_attrs = _get_keep_attrs(default=False)
868862

869863
dim = either_dict_or_kwargs(dim, window_kwargs, "rolling")
870864
return self._rolling_cls(

0 commit comments

Comments
 (0)