-
-
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
Update DataTree repr to indicate inheritance #9470
Conversation
This is ready for review now. |
""" | ||
<xarray.DataTree 'child'> | ||
Group: /child | ||
Dimensions: (x: 1, y: 1) |
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.
Isn't this one incorrect? x
should not be inherited in this case, because it's defined only on parents' data variables, not parents' coordinate variables?
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.
We do still want to include it here, because it is included in the alignment checks. If you tried to insert an array with a different sized x
dimension on "child"
it would raise an error.
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.
Hmm. But it would raise an error basically because it didn't align with a variable that only exists in the parent (and is not inherited)? I feel like our discussions about this are being a bit vague in distinguishing between "aligns with data in a node" and "aligns with whole tree".
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.
This is looking really really good - I'm really pleased with how neat this is turning out!
Only one comment about a case that confused me.
def _inherited_vars(mapping: ChainMap) -> dict: | ||
return {k: v for k, v in mapping.parents.items() if k not in mapping.maps[0]} |
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 wonder if there is anywhere else that this function might be useful.
@TomNicholas does this look good to merge to you? |
I don't have any changes to suggest but I'm still wrapping my head around this: So basically alignment is relative to all dimensions in the tree, not just inherited coordinates? (Because we check up the ancestors recursively.) Therefore alignment with ancestors and inheritance of coordinates are really two separate new features, in that we could have theoretically implemented the former without the latter. And your logic (both here and in the repr of I think that all makes sense to me now. |
Correct -- alignment in Xarray is defined by both coordinates and dimensions. So it depends on inherited dimensions, not just inherited coordinates.
Yes, in theory. Though in practice, inheriting coordinates (and dimensions) on sub-trees is the easiest way to ensure alignment. Otherwise you could pull out a sub-tree and use it somewhere else without coordinates, and it could align erroroneously. |
* main: (26 commits) Forbid modifying names of DataTree objects with parents (pydata#9494) DAS-2155 - Merge datatree documentation into main docs. (pydata#9033) Make illegal path-like variable names when constructing a DataTree from a Dataset (pydata#9378) Ensure TreeNode doesn't copy in-place (pydata#9482) `open_groups` for zarr backends (pydata#9469) Update pyproject.toml (pydata#9484) New whatsnew section (pydata#9483) Release notes for v2024.09.0 (pydata#9480) Fix `DataTree.coords.__setitem__` by adding `DataTreeCoordinates` class (pydata#9451) Rename DataTree's "ds" and "data" to "dataset" (pydata#9476) Update DataTree repr to indicate inheritance (pydata#9470) Bump pypa/gh-action-pypi-publish in the actions group (pydata#9460) Repo checker (pydata#9450) Add days_in_year and decimal_year to dt accessor (pydata#9105) remove parent argument from DataTree.__init__ (pydata#9465) Fix inheritance in DataTree.copy() (pydata#9457) Implement `DataTree.__delitem__` (pydata#9453) Add ASV for datatree.from_dict (pydata#9459) Make the first argument in DataTree.from_dict positional only (pydata#9446) Fix typos across the code, doc and comments (pydata#9443) ...
* main: (29 commits) Release notes for v2024.09.0 (pydata#9480) Fix `DataTree.coords.__setitem__` by adding `DataTreeCoordinates` class (pydata#9451) Rename DataTree's "ds" and "data" to "dataset" (pydata#9476) Update DataTree repr to indicate inheritance (pydata#9470) Bump pypa/gh-action-pypi-publish in the actions group (pydata#9460) Repo checker (pydata#9450) Add days_in_year and decimal_year to dt accessor (pydata#9105) remove parent argument from DataTree.__init__ (pydata#9465) Fix inheritance in DataTree.copy() (pydata#9457) Implement `DataTree.__delitem__` (pydata#9453) Add ASV for datatree.from_dict (pydata#9459) Make the first argument in DataTree.from_dict positional only (pydata#9446) Fix typos across the code, doc and comments (pydata#9443) DataTree should not be "Generic" (pydata#9445) Disallow passing a DataArray as data into the DataTree constructor (pydata#9444) Support additional dtypes in `resample` (pydata#9413) Shallow copy parent and children in DataTree constructor (pydata#9297) Bump minimum versions for dependencies (pydata#9434) Always include at least one category in random test data (pydata#9436) Avoid deep-copy when constructing groupby codes (pydata#9429) ...
* Update DataTree repr to indicate inheritance Fixes pydata#9463 * fix whitespace * add more repr tests, fix failure * fix failure on windows * fix repr for inherited dimensions
Still need a few more tests.
The HTML formatter will also need updates (not as part of this PR)