Skip to content
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

sort when encoding coordinates for deterministic outputs #8034

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

itcarroll
Copy link
Contributor

@itcarroll itcarroll commented Jul 31, 2023

The PR changes conventions._encode_coordinates to add sorted during the creation of "coordinates" strings de novo. It does not touch user-specified coordinates attributes or encodings.

The PR adds a test, but also changes two pre-existing tests that allowed for non-deterministic ordering of the coordinates string.

In reviewing the netCDF data model and CF convenstions, I confirmed that there is no requirement on the ordering of names in the coordinates attribute. I also learned that the global coordinates attribute created by XArray for non-dimension coordinates that are not associated with a variable is not compliant with CF conventions, as was discussed in 2014. In 2021, CF-Conventions 1.9 added "Domain Variables", which appear to provide a CF compliant way to handle this situation. I will likely open an enhancement issue to weigh making that change.

@itcarroll itcarroll changed the title sort assignments to .attr["coordinates"] sort when encoding coordinates for deterministic outputs Aug 1, 2023
Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @itcarroll

@dcherian dcherian added the plan to merge Final call for comments label Aug 2, 2023
Copy link
Collaborator

@headtr1ck headtr1ck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run into this issue as well in the past, thanks for fixing this (and reporting it in the first place)!

doc/whats-new.rst Outdated Show resolved Hide resolved
doc/whats-new.rst Outdated Show resolved Hide resolved
@dcherian dcherian enabled auto-merge (squash) August 3, 2023 16:04
@dcherian dcherian merged commit fb6bbbe into pydata:main Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

non-deterministic ordering within "coordinates" attribute written by .to_netcdf
3 participants