-
Notifications
You must be signed in to change notification settings - Fork 2
Fix propagation of global attributes to child datasets and variables #72
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
base: main
Are you sure you want to change the base?
Changes from all commits
c84f97f
b05b757
611b743
3f66e9a
224478e
e27d640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ dependencies: | |
| # Library Dependencies | ||
| - click | ||
| - fsspec | ||
| - isodate>=0.7.2 | ||
| - pyyaml | ||
| - tabulate | ||
| - xarray | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,21 +62,33 @@ def apply_rule( | |
|
|
||
|
|
||
| def _visit_datatree_node(rule_op: RuleOp, context: RuleContextImpl, node: DataTreeNode): | ||
| # Get a copy of the current node's attrs. | ||
| # These will be merged into each child's attrs so that attributes | ||
| # defined on parent nodes are inherited by all descendants. | ||
| attrs = node.datatree.attrs.copy() | ||
|
|
||
| with context.use_state(node=node): | ||
| rule_op.validate_datatree(context, node) | ||
|
|
||
| if node.datatree.is_leaf: | ||
| # Inherit attrs from the parent datatree into the child dataset | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just explains what the code does, but this is obvious. Please answer the question why this is done. What issues is solved by copying attributes. |
||
| dataset = node.datatree.dataset.copy() | ||
| dataset.attrs = {**attrs, **dataset.attrs} | ||
| _visit_dataset_node( | ||
| rule_op, | ||
| context, | ||
| DatasetNode( | ||
| parent=node, | ||
| path=f"{node.path}/{node.datatree.name}", | ||
| name=node.datatree.name, | ||
| dataset=node.datatree.dataset, | ||
| dataset=dataset, | ||
| ), | ||
| ) | ||
| else: | ||
| for name, datatree in node.datatree.children.items(): | ||
| # Inherit attrs from the parent datatree into the child datatree | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| datatree = datatree.copy() | ||
| datatree.attrs = {**attrs, **datatree.attrs} | ||
| _visit_datatree_node( | ||
| rule_op, | ||
| context, | ||
|
|
||
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.
Why? To me this sounds like an xarray bug for which we provide a workaround here. Why do we have to inherit them manually? To me it seems we are copying attributes from a parent group into a child group - that would be wrong as it does not reflect the true physical structure of the Zarr dataset.