Support DataArray objects and nested dicts in DataTree.from_dict#10658
Conversation
|
Thanks for adding this at @shoyer! Do you think it would be worth adding another round trip test for Here is what I did based on DataArray.from_dict |
|
|
||
| Or equivalently from a dict of values coercible to DataArray objects: | ||
|
|
||
| >>> dt2 = DataTree.from_dict({"/a": 1, "/b/c": 2, "/b/d": 3}, coords={"/x": 0}) |
There was a problem hiding this comment.
Is this supposed to create a group with the name"/a"? On my end I am just seeing ('/', '/b') and the data variable with the name "a".
There was a problem hiding this comment.
This example was supposed to show creating a variable "a". I've replaced this with something a bit more concrete to illustrate the intended usage.
772c6c8 to
1baf002
Compare
So unfortunately this doesn't work. The issue is that
I'm not sure it makes sense to combine both in a single function. In particular, there is some ambiguity about whether Instead, I think we should have a dedicated methods |
|
I've changed |
|
@TomNicholas any thoughts? |
etienneschalk
left a comment
There was a problem hiding this comment.
Some general comments and questions out of curiosity
|
@TomNicholas I would really appreciate your feedback on the API here, even just the docstring for |
|
Last call for review here! |
eni-awowale
left a comment
There was a problem hiding this comment.
I like the addition of the nested flag and the dt2 example!
This PR adds three features to the
DataTree.from_dictconstructor:DataArrayobjects and anything that can be coerced into aDataArrayvia theDatasetconstructor.coordsargument for explicitly specifying coordinates.nested=Trueis passed tofrom_dict().Explicitly requiring
nested=Truecould potentially be relaxed, now or in the future. The main advantage is that it keeps the core signature simpler (allowing for more type safety), and avoids potential overlap in type signatures with "native" dict format (#9074).Fixes #9539, #9486
whats-new.rst