-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix DataTree path like assignment GH9485 GH9490 GH9978 #11001
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
Conversation
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
| def handle_child(name, child): | ||
| """ | ||
| Decide whether to call _set_item or _set_parent. If the child name is a | ||
| path, we call ._set_item to make sure any intermediate nodes are also | ||
| created. When name is a path there will be nested calls of children due to | ||
| the setter decorator, and the fact ._set_item assigns to the children | ||
| attribute. | ||
| """ | ||
| if "/" in name: | ||
| # Path like node name. Create node at appropriate level of nesting. |
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'm worried that this design change will silently break things somehow. It effectively allows violating an intended design invariant (that node names do not have slashes) then attempts to ensure that it cleans up after itself. I would much prefer to solve this in some way that never violates the invariant, even internally.
Awesome! Thank you for taking the initiative here!
We did make them illegal in variable names, and intended to make them illegal in child names too (see #9490, which we apparently didn't get around to implementing yet). I think all sorts of things could break if we try to reverse that right now, because This PR changes a lot of behaviour - can it be broken up? I'm unclear whether you have implemented one change that addresses 3 issues, or 3 changes that address 3 issues. At the very least the coordinate feature seems easily separable. In general a larger number of smaller, more targeted PRs is preferable.
This seems useful, but also it sounds like this method both mutates state and has a return value, which is considered unpythonic (as @shoyer mentions in #9196). I'm worried that could lead to unintentional side-effects. I think a safer approach here is a sequence of small, separate PRs, that address #9490, then #9978 (ideally without adding any new methods - there presumably must be a bug in an existing method that causes this), then finally #9498. I really appreciate you diving in here! |
|
Thanks so much for the review @TomNicholas!
I agree, and also agree with your other points. I'll close this PR and re-open once I've revised! |
|
Thank you so much! |
DataTreecauses aRecursionError#9978whats-new.rstAddresses a number of issues related to initializing
DataTreeobjects with path like names. Not sure if @TomNicholas is still working on these, but thought I'd have a go.Recursion Issue #9978
As discussed by @dawiedotcom in #9978, commands like
currently cause infinite recursion. To fix, we amend the
childrensetter to allow path like names, creating intermediate nodes using._set_item. Note the discussion in #9378 proposes making path like names illegal, but I think allowing them is more natural. With this PR, the above command will now returnDataTree.updateInconsistencies #9485Fix the
DataTree.updatemethod by adapting the approach suggested by @TomNicholas in #9485. Specifically, rewrite the existingupdatemethod as_update_local_node, which assumes the names given inotherare not path like, and all updates apply to given node. Then write a newupdatemethod which groups the items ofotherinto those items specific to each node, then calls_update_local_nodeon each group.xarray.Dataarrayandxarray.Variablevalues inotherare handled as before.xarray.Datasetvalues inother, assuming the user's intent is to create a node at the given path with the given dataset, or replace the node's dataset if it already exists.updateand__setitem__give identical results.With this PR, commands like
will return
Child Node Coordinate Assignment #9485
As discussed by @shoyer in #9485, allow for assignment to child node coordinates using path like names. The commands
now return
General Comments
These fixes are accomplished by adding
DataTree._get_target_object, which returns the object at the given path if it exists, or creates an empty node at that path using_set_itemif it doesn't. We also addNodePath._get_componentswhich returnsself.parentandself.nameprovidedself.nameexists, or raises an error otherwise.