Fix missing coordinate attributes after apply_ufunc operations #10083
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix missing coordinates after apply_ufunc operations.
test_keep_coordattrs
whats-new.rst
Dear code owners,
I have put some effort in trying to prevent missing coordinate attributes. The benefit of this is best seen in missingcoords.pdf. I do run into some issues with testing however. As far as I can tell, the failed tests (see pytest_output.txt) are caused mainly by a few tests in tests/computation.py that only pass if some data can be merged depending on the keep_attrs value. This is a bit confusing to me as I expected the keep_attrs argument to only be relevant for the data itself, not the coordinates. For example, when you call DataArray.mean(dim, keep_attrs=False), the coordinate attributes are still present on the result even though its data does not have attributes. To me, as a user of your package, this behaviour is really great and I would expect coordinates to keep their attributes during various operations, including the apply_ufunc ops. I have intentionally set the compat value to "no_conflicts" in my fix, because I could not come up with a use case where one would merge dataarrays together with different coordinate attributes. Differing coordinate attributes may imply the coordinates have a different physical meaning, so I would expect a merge error. This would mean that the failed tests in the attachment would need to be reconsidered, however.
Do you think this is the right direction to go? I would like to hear your vision on this. Maybe I'm just overlooking something important here. I am happy to help out in resolving this issue.
Kind regards,
Jasper
missingcoords.pdf
pytest_output.txt