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.__delitem__ should support deleting variables, not only child nodes #9221

Closed
shoyer opened this issue Jul 9, 2024 · 0 comments · Fixed by #9453
Closed

DataTree.__delitem__ should support deleting variables, not only child nodes #9221

shoyer opened this issue Jul 9, 2024 · 0 comments · Fixed by #9453
Labels
bug topic-DataTree Related to the implementation of a DataTree class

Comments

@shoyer
Copy link
Member

shoyer commented Jul 9, 2024

What happened?

Currently this raises a very uninformative error message:

In [1]: from xarray.core.datatree import DataTree

In [2]: tree = DataTree()

In [3]: tree['x'] = 1

In [4]: tree
Out[4]:
<xarray.DataTree>
Group: /
    Dimensions:  ()
    Data variables:
        x        int64 8B 1

In [5]: del tree['x']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[5], line 1
----> 1 del tree['x']

File ~/dev/xarray/xarray/core/treenode.py:563, in TreeNode.__delitem__(self, key)
    561     child.orphan()
    562 else:
--> 563     raise KeyError("Cannot delete")

KeyError: 'Cannot delete'

What did you expect to happen?

The variable 'x' should be deleted, consistent with __getitem__. Short of that, we should raise an informative error message about why this isn't possible.

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

Successfully merging a pull request may close this issue.

2 participants