Skip to content

Commit

Permalink
rolling keep_attrs & default True (#4510)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mathause authored Nov 9, 2020
1 parent 7ce0110 commit 1735892
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 89 deletions.
8 changes: 8 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ v0.16.2 (unreleased)
Breaking changes
~~~~~~~~~~~~~~~~

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

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

Documentation
Expand Down
6 changes: 0 additions & 6 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,6 @@ def rolling(
setting min_periods equal to the size of the window.
center : bool or mapping, default: False
Set the labels at the center of the window.
keep_attrs : bool, optional
If True, the object's attributes (`attrs`) will be copied from
the original object to the new one. If False (default), the new
object will be returned without attributes.
**window_kwargs : optional
The keyword arguments form of ``dim``.
One of dim or window_kwargs must be provided.
Expand Down Expand Up @@ -863,8 +859,6 @@ def rolling(
core.rolling.DataArrayRolling
core.rolling.DatasetRolling
"""
if keep_attrs is None:
keep_attrs = _get_keep_attrs(default=False)

dim = either_dict_or_kwargs(dim, window_kwargs, "rolling")
return self._rolling_cls(
Expand Down
Loading

0 comments on commit 1735892

Please sign in to comment.