This repository was archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
cleanup subtree assignment in io open functions #96
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,16 +68,8 @@ def _open_datatree_netcdf(filename: str, **kwargs) -> DataTree: | |
tree_root = DataTree.from_dict({"/": ds}) | ||
for path in _iter_nc_groups(ncds): | ||
subgroup_ds = open_dataset(filename, group=path, **kwargs) | ||
tree_root[path] = DataTree(name=path, data=subgroup_ds) | ||
|
||
# TODO refactor to use __setitem__ once creation of new nodes by assigning Dataset works again | ||
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 comment was actually referring to the difference between
the latter of which currently doesn't work, but also perhaps doesn't need to. |
||
node_name = NodePath(path).name | ||
new_node: DataTree = DataTree(name=node_name, data=subgroup_ds) | ||
Comment on lines
-73
to
-74
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. Are you sure your new code behaves the same way as this old code? Because previously we were naming new nodes as |
||
tree_root._set_item( | ||
path, | ||
new_node, | ||
allow_overwrite=False, | ||
new_nodes_along_path=True, | ||
) | ||
return tree_root | ||
|
||
|
||
|
@@ -93,15 +85,8 @@ def _open_datatree_zarr(store, **kwargs) -> DataTree: | |
except zarr.errors.PathNotFoundError: | ||
subgroup_ds = Dataset() | ||
|
||
# TODO refactor to use __setitem__ once creation of new nodes by assigning Dataset works again | ||
node_name = NodePath(path).name | ||
new_node: DataTree = DataTree(name=node_name, data=subgroup_ds) | ||
tree_root._set_item( | ||
path, | ||
new_node, | ||
allow_overwrite=False, | ||
new_nodes_along_path=True, | ||
) | ||
tree_root[path] = DataTree(name=path, data=subgroup_ds) | ||
|
||
return tree_root | ||
|
||
|
||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Using
__setitem__
instead of_set_item
here can behave differently, for instance if a group appeared twice one method would allow overwriting by default and the other wouldn't.Another difference is that
__setitem__
creates intermediate nodes, i.e. ifdt
only has one node, then callingdt['/root/a/b/c/d/e/foo'] = DataTree()
would create nodes/root/a
,/root/a/b/
,/root/a/b/c
... etc. whereas_set_item
would raise.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.
The reason I made the
_set_item_
method was for internal developer API so that this kind of behaviour could be controlled more explicitly.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.
Thanks for the explanation.