Skip to content
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

datatree: drop_vars issue? #9336

Open
keewis opened this issue Aug 13, 2024 · 0 comments
Open

datatree: drop_vars issue? #9336

keewis opened this issue Aug 13, 2024 · 0 comments
Labels
topic-DataTree Related to the implementation of a DataTree class

Comments

@keewis
Copy link
Collaborator

keewis commented Aug 13, 2024

What is your issue?

I don't know if it is an issue (datatree==0.0.14) but, at least, it is an error that could appear quite easily:

import datatree
import xarray as xr
ds = xr.DataArray([[1,2,3]],dims=['a','b'])
dt =datatree.DataTree()
dt['A'] = ds
dt['B'] = ds
for grp in dt.groups:
    vars2drop = [vv for vv in dt[grp] if 'example' in vv]
    dt[grp] = dt[grp].drop_vars(vars2drop)

the case that would be problematic is:

dt['/'] = dt['/'].drop_vars([])

the error raised is:

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/datatree/datatree.py:852, in DataTree.__setitem__(self, key, value)
    848 elif isinstance(key, str):
    849     # TODO should possibly deal with hashables in general?
    850     # path-like: a name of a node/variable, or path to a node/variable
    851     path = NodePath(key)
--> 852     return self._set_item(path, value, new_nodes_along_path=True)
    853 else:
    854     raise ValueError("Invalid format for key")

File ~/micromamba/envs/micromamba1/lib/python3.10/site-packages/datatree/treenode.py:494, in TreeNode._set_item(self, path, item, new_nodes_along_path, allow_overwrite)
    491     path = NodePath(path)
    493 if not path.name:
--> 494     raise ValueError("Can't set an item under a path which has no name")
    496 if path.root:
    497     # absolute path
    498     current_node = self.root

ValueError: Can't set an item under a path which has no name

Originally posted by @agrouaze in xarray-contrib/datatree#316 (comment)

@keewis keewis added needs triage Issue that has not been reviewed by xarray team member and removed needs triage Issue that has not been reviewed by xarray team member labels Aug 13, 2024
@TomNicholas TomNicholas added the topic-DataTree Related to the implementation of a DataTree class label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-DataTree Related to the implementation of a DataTree class
Projects
None yet
Development

No branches or pull requests

2 participants