-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix destagger attrs #97
Conversation
Very good catch, and an important thing to fix before releasing this! I think I missed this because of keep_attrs settings (which, I'm going to go look if there is a context-based way of having different keep_attrs settings for use in our tests without changing global state). I would recommend, however, a different implementation approach than used here. Attrs (and encoding...that's one I forgot about too) are able to exist on the Lines 73 to 79 in 290c2e7
should get replaced with return xr.Variable(
dims=tuple(str(unstag_dim_name) if dim == stagger_dim else dim for dim in center_mean.dims),
data=center_mean.data,
attrs=_drop_attrs(datavar.attrs, ('stagger',)),
encoding=datavar.encoding,
fastpath=True,
) (i.e., use original @lpilz Would you want to implement these changes in this PR? Otherwise, I could put together a replacement PR if not? Also, if you want to go ahead on implementing this, I'd recommend against modifying the data attrs in the tests. For example, instead of if 'stagger' in data.attrs:
data.attrs.pop('stagger')
assert set(destaggered.attrs.keys()) == set(data.attrs.keys()) have assert set(destaggered.attrs) == set(data.attrs) - set(('stagger',)) |
Thanks for the hints, I don't know why I didn't see the obvious fix... I applied the changes you requested, hope this works. I implemented the set subtraction with |
No, that's definitely better! The reason I did it the way I did instead of thinking of the more obvious construction is that I've gotten into the bad habit of over-using |
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.
Generally looks good; thanks for updating the approach! Would you be able to add (or update existing) tests for proper attr handling in tests/test_destagger
, as well as making the one small change below to also fix encoding
?
Co-authored-by: jthielen <jon@thielen.science>
Change Summary
When using the
destagger
method ofDataset
andDataArray
accessors, variable attributes were getting removed. Attributes likeunits
orgrid_mapping
are however important for processing of data, e.g. withmetpy
.Related issue number
Closing #96
Checklist
Documentation reflects the changes where applicable