-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
rolling keep_attrs & default True #4510
Conversation
xarray/core/common.py
Outdated
If True (default), the object's attributes (`attrs`) will be copied | ||
from the original object to the new one. If False, the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If True (default), the object's attributes (`attrs`) will be copied | |
from the original object to the new one. If False, the new | |
If None (default) or True, the object's attributes (`attrs`) will be | |
copied from the original object to the new one. If False, the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd replace the (default)
and the , optional
in the type spec with , default: None
Great, thanks! Are the global configs still being honored in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ready for a review. It was a bit more complicated than anticipated - I had to thread keep_attrs
through a lot of functions. So may not be trivial to check.
To summarize:
- Per where should keep_attrs be set in groupby, resample, weighted etc.? #4513 this switches from
ds.rolling(..., keep_attrs=False).mean()
tods.rolling(...).mean(keep_attrs=False)
& prints a deprecation warning. - Per # Keep attrs by default? (keep_attrs) #3891 this now keeps attrs per default (it respects the global
keep_attrs
setting) - Fixes ds.rolling() drops attributes and name #4497
f"Reductions are applied along the rolling dimension(s) " | ||
f"'{self.dim}'. Passing the 'dim' kwarg to reduction " | ||
f"operations has no effect.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning used to be:
"and will raise an error in xarray 0.16.0"
I decided to continue warning and not raise an error - objections?
Wow, this was quite the herculean effort @mathause . Thanks. That solves any questions I had about whether the global configs are being honored... To the extent we have to do more of these, we could consider whether we need to add |
Any other thoughts before we merge? |
I added a test to ensure While working on this I thought |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks great. I read through the tests carefully and browed the code. I would merge unless others have thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing a global default and kwarg revealed some more issues. Should be fixed now.
I realize this does still not preserve the encoding. Not sure what our general take is on that.
) | ||
else: | ||
dataset[key] = da | ||
return Dataset(dataset, coords=self.obj.coords).isel( | ||
dataset[key] = da.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now do a deep copy here. I think this is safer. Else non-rolled DataArrays were connected to the original obj.
Thanks again @mathause ! |
isort . && black . && mypy . && flake8
whats-new.rst
Only global attributes were retained for
rolling
operations.DataArray
s would loose their attrs.As per #3891 (comment) I also changed the default to
True
.Note #4497 also mentions propagation of the name. This is not yet implemented.