-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disallow passing a DataArray as data into the DataTree constructor #9444
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
I don't think there's a good reason to support syntax like `DataTree(DataArray(...))`, when it's easy enough to explicitly convert with `to_dataset()`. `Dataset(DataArray(...))` currently raises an error, so this feels a bit inconsistent. If this was intended for the sake of usability, then I think supporting a dict (that gets coerced into a Dataset) in the DataTree constructor would be much helpful. We can consider adding this later.
Makes sense. This PR just needs a test for the new behaviour. (Does you assigning me to the issue mean that you want me to finish off this PR by pushing to the branch or just to review it @shoyer ? 😆 ) |
Ooops, forgot to the push the tests -- those were on a separate branch. Assigning this to you means I'm asking you for the review :). I can write my own tests! |
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.
Haha okay! I was just unsure because the "request review from ..." button is different to the "assign issue to ..." button.
This looks good though! That remaining mypy failure is due to str vs hashable keys I think.
* 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) ...
I don't think there's a good reason to support syntax like
DataTree(DataArray(...))
, when it's easy enough to explicitly convert withto_dataset()
.Dataset(DataArray(...))
currently raises an error, so this feels a bit inconsistent.If this was intended for the sake of usability, then I think supporting a dict (that gets coerced into a Dataset) in the DataTree constructor would be much helpful. We can consider adding this later.
@TomNicholas