This repository was archived by the owner on Oct 24, 2024. It is now read-only.
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Error in datatree.DataTree.sel when attributes are set #262
Closed
Description
Hi, thank you for your work on datatree
.
I've been using datatree
in the context of https://github.com/spatial-image/multiscale-spatial-image and stumbled upon an error: If I try to call datatree.DataTree.sel
on a datatree without attributes, the function works as expected. However if the tree has an attribute set, I get the following error:
site-packages/xarray/core/indexing.py:139, in group_indexers_by_index(obj, indexers, options)
137 raise KeyError(f"no index found for coordinate {key!r}")
138 elif key not in obj.dims:
--> 139 raise KeyError(f"{key!r} is not a valid dimension or coordinate")
140 elif len(options):
141 raise ValueError(
142 f"cannot supply selection options {options!r} for dimension {key!r}"
143 "that has no associated coordinate or index"
144 )
KeyError: "'dim_0' is not a valid dimension or coordinate"
Here's a reproducible example:
import datatree
import xarray as xr
import numpy as np
xs = xr.Dataset({'testvar': xr.DataArray(np.ones((2,3)))})
dt = datatree.DataTree.from_dict({'node1': xs1, 'node2': xs1})
dt.attrs['test_key'] = 1 # sel works fine without this line
dt.sel({'dim_0': 0})
I'm using datatree==0.0.12
.
Metadata
Metadata
Assignees
Labels
No labels