You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating an xarray.DataTree object, passing the optional children parameter with / in a key of the dictionary produces an infinite recursion loop.
It appears that a ValueError: node names cannot contain forward slashes is raised, but the program then gets stuck in a mutual recursive loop between
child._set_parent(new_parent=self, child_name=name) # xarray/core/treenode.py line 333
and
self._attach(new_parent, child_name) # xarray/core/treenode.py line 115
This happens before the ValueError can be handled by the call to xarray.DataTree.
What did you expect to happen?
Either of the following:
Just raise ValueError("node names cannot contain forward slashes"), without the recursion issue.
Even better: using / in the keys of the children parameter produces nested DataTree objects. This was be behaviour in xarray-contrib/datatree.
Minimal Complete Verifiable Example
fromxarrayimportDataTree# Wrapping this in try, except handles the RecursionError, not the ValueErrordt=DataTree(children={'a/b': DataTree()})
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
I tested this on the latest main branch in a new conda environment, but it appears the issue is present in every version of xarray since the introduction of DataTree.
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
What happened?
When creating an
xarray.DataTree
object, passing the optionalchildren
parameter with/
in a key of the dictionary produces an infinite recursion loop.It appears that a
ValueError: node names cannot contain forward slashes
is raised, but the program then gets stuck in a mutual recursive loop betweenand
This happens before the
ValueError
can be handled by the call toxarray.DataTree
.What did you expect to happen?
Either of the following:
raise ValueError("node names cannot contain forward slashes")
, without the recursion issue./
in the keys of the children parameter produces nested DataTree objects. This was be behaviour inxarray-contrib/datatree
.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
I tested this on the latest
main
branch in a new conda environment, but it appears the issue is present in every version of xarray since the introduction ofDataTree
.Environment
INSTALLED VERSIONS
commit: None
python: 3.13.1 (main, Dec 4 2024, 18:05:56) [GCC 14.2.1 20240910]
python-bits: 64
OS: Linux
OS-release: 6.12.9-arch1-1
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: 4.9.4-development
xarray: 2025.1.1
pandas: 2.2.3
numpy: 2.2.1
scipy: 1.15.1
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.10.0
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: None
conda: None
pytest: 8.3.4
mypy: None
IPython: None
sphinx: None
The text was updated successfully, but these errors were encountered: