xarray-datatree
raw JSON → 0.0.15 verified Mon Apr 27 auth: no python
Provides hierarchical tree-like data structures (DataTree) for xarray, enabling nested datasets. Currently at version 0.0.15, with slow development and no stable release. It is experimental and may have breaking changes between minor versions.
pip install xarray-datatree Common errors
error ModuleNotFoundError: No module named 'xarray_datatree' ↓
cause Import path renamed to 'datatree' in version 0.0.11.
fix
Use
from datatree import DataTree. error AttributeError: 'DataTree' object has no attribute 'children' ↓
cause The children property was removed or renamed in later versions.
fix
Use
dt.tree.children or iterate over dt.subtree; check documentation for current API. Warnings
breaking Import path changed from xarray_datatree to datatree in version 0.0.11. Old imports will raise ModuleNotFoundError. ↓
fix Use `from datatree import DataTree` instead of `from xarray_datatree import DataTree`.
breaking API is highly unstable; no backward compatibility guarantees. Expect interfaces to change between minor versions. ↓
fix Pin version strictly and test upgrades carefully.
gotcha Operations like `dt.to_netcdf()` may drop existing variables if dataset passed has different encoding. Always validate roundtrip. ↓
fix Use explicit encoding settings or check netCDF file after writing.
Imports
- DataTree wrong
from xarray_datatree import DataTreecorrectfrom datatree import DataTree
Quickstart
from datatree import DataTree
import xarray as xr
# Create a nested tree
dt = DataTree.from_dict({
"/": xr.Dataset({"x": [1, 2]}),
"/subgroup": xr.Dataset({"y": [3, 4]})
})
print(dt)