-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
bugtopic-DataTreeRelated to the implementation of a DataTree classRelated to the implementation of a DataTree class
Description
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.
TomNicholas
Metadata
Metadata
Assignees
Labels
bugtopic-DataTreeRelated to the implementation of a DataTree classRelated to the implementation of a DataTree class