-
-
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
Fix dataarray drop attrs #10030
Fix dataarray drop attrs #10030
Conversation
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
8695590
to
f3d7414
Compare
A welcome follow-up would be adding Could we add a whatsnew and then merge? |
e1f39a7
to
f2175fe
Compare
I added attrs to I also updated the |
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.
Excellent! Thanks!
@headtr1ck you need to approve for us to merge |
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.
Will approve to not delay this further, but I think there is still a flaw in the logic that should be fixed.
xarray/core/dataarray.py
Outdated
if attrs is _default: | ||
attrs = copy.copy(self.attrs) | ||
else: | ||
variable = self.variable.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 don't think this is correct.
This will overwrite a given variable.
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.
Yes, true, I'll fix this.
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.
thanks a lot @headtr1ck , sorry to have missed this
I fixed the issue @headtr1ck raised, that replacing a variable and attributes simultaneously would "skip" the variable. Further, I added tests for
(2) I made the assumption that if a variable and attributes are replaced simultaneously, the passed attributes override the variable attributes. And further, if the replacement variable contains attributes they should replace any original attributes. I made both explicit in the test. I'm happy to change the behavior or add a warning. |
Great — we do try and test private methods, but sometimes assume they're implicitly tested. When making a change to them, adding a test like you most recently did makes a lot of sense. Thanks a lot @j-haacker ! Appreciate you making the underlying code better as well as fixing the immediate problem! |
This PR is related to Issue #10027
It fixes the issue and adds tests to prevent similar issues in future.
whats-new.rst
I did not document the change in whats-new.
I'm also not 100 % happy with the solution. I would welcome an experienced contributor to review the changes.