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

Fix writing of DataTree subgroups to zarr or netCDF #9677

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 24, 2024

Consider a DataTree with a group, e.g.,
tree = DataTree.from_dict({'/': ... '/child': ...})

If we write tree['/child'] to disk, the result should have groups relative to '/child', so writing and reading from the same path restores the same object.

In addition, coordinates defined at the root should be written to disk instead of being omitted.

  • Tests added

Consider a DataTree with a group, e.g.,
`tree = DataTree.from_dict({'/': ... '/child': ...})`

If we write `tree['/child']` to disk, the result should have groups
relative to `'/child'`, so writing and reading from the same path
restores the same object.

In addition, coordinates defined at the root should be written to
disk instead of being omitted.
@TomNicholas TomNicholas added topic-backends topic-DataTree Related to the implementation of a DataTree class labels Oct 24, 2024
Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

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

Good catch!

Too slow for the v2024.10.0 release but this is important so we should release again very soon.

As discussed in the last xarray meeting, this defaults to
write_inherited_coords=True, which has a little more overhead but means
you always get coordinates when opening a sub-group.
@@ -1609,6 +1610,11 @@ def to_netcdf(
group : str, optional
Path to the netCDF4 group in the given file to open as the root group
of the ``DataTree``. Currently, specifying a group is not supported.
write_inherited_coords : bool, default: True
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens at read-time? Do we normalize and remove duplicated coords by default? If so, I think we should change so that does not happen by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

what happens at read-time? Do we normalize and remove duplicated coords by default?

Yes, this is what happens.

If so, I think we should change so that does not happen by default.

Can you clarify what you mean here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-backends topic-DataTree Related to the implementation of a DataTree class
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants