Fix misleading DataTree constructor error message (#11514) - #11564
Open
IMGillusion wants to merge 2 commits into
Open
Fix misleading DataTree constructor error message (#11514)#11564IMGillusion wants to merge 2 commits into
DataTree constructor error message (#11514)#11564IMGillusion wants to merge 2 commits into
Conversation
The `DataTree` constructor only accepts an `xarray.Dataset`, `xarray.Coordinates`, or `None` as its `dataset` argument, but the TypeError raised for any other input incorrectly listed `dict` as a valid type (a leftover from an earlier API iteration). Update the message to name `xarray.Coordinates` so it is not misleading. Add a regression test in `TestTreeCreation.test_data_arg`.
for more information, see https://pre-commit.ci
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #11514.
What happened
xr.DataTree(dict())raisesbut
DataTree.__init__only accepts anxarray.Dataset,xarray.Coordinates, orNonefor itsdatasetargument —_to_new_datasethas branches for exactly those three. Thedictin the message is a leftover from an earlier API iteration and is misleading (it advertises a type the constructor does not accept).Change
Update the
TypeErrormessage in_to_new_dataset(xarray/core/datatree.py) to namexarray.Coordinatesinstead ofdict. This is a copy-only fix — it does not change constructor behaviour (acceptingdictwould be a separate, larger API decision).Test
Added a regression assertion to
TestTreeCreation.test_data_arg:DataTree(dataset=dict())must raise aTypeErrorwhose message referencesxarray.Coordinates.Validation
dict), fixed version passestest_datatree.pypasses (151 passed, 5 skipped, 5 xfailed), no regressionsDataTree(xr.Coordinates(...))still constructs as expected