-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
bugneeds triageIssue that has not been reviewed by xarray team memberIssue that has not been reviewed by xarray team member
Description
What happened?
xarray doesn't recognise a zarr datatree because the zarr backend isn't configured with support_groups=True. This causes xarray.open_datatree to fail with the following exception:
Traceback (most recent call last):
File "/home/simon/code/xarray/xarray/tests/test_dt_zarr.py", line 23, in <module>
dt = xr.open_datatree(PATH)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/simon/code/xarray/xarray/backends/api.py", line 1047, in open_datatree
engine = plugins.guess_engine(filename_or_obj, must_support_groups=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/simon/code/xarray/xarray/backends/plugins.py", line 212, in guess_engine
raise ValueError(error_msg)
ValueError: did not find a match in any of xarray's currently installed IO backends ['h5netcdf', 'scipy', 'netcdf4', 'pydap', 'zarr']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
https://docs.xarray.dev/en/stable/user-guide/io.htmlThe following PR introduced the BackendEntrypoint.support_groups class variable:
What did you expect to happen?
open_datatree should be able to guess the engine
Minimal Complete Verifiable Example
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!
import xarray as xr
xr.show_versions()
# your reproducer code ...
import xarray as xr
def modify(ds):
return ds
set1_data = modify(xr.Dataset({"a": 0, "b": 1}))
set2_data = modify(xr.Dataset({"a": ("x", [2, 3]), "b": ("x", [0.1, 0.2])}))
root_data = modify(xr.Dataset({"a": ("y", [6, 7, 8]), "set0": ("x", [9, 10])}))
root = xr.DataTree.from_dict(
{
"/": root_data,
"/set1": set1_data,
"/set1/set1": None,
"/set1/set2": None,
"/set2": set2_data,
"/set2/set1": None,
"/set3": None,
})
PATH = "/tmp/datatree.zarr"
root.to_zarr(PATH, compute=True, consolidated=True, mode="w")
dt = xr.open_datatree(PATH)Steps to reproduce
No response
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.
Relevant log output
Traceback (most recent call last):
File "/home/simon/code/xarray/xarray/tests/test_dt_zarr.py", line 23, in <module>
dt = xr.open_datatree(PATH)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/simon/code/xarray/xarray/backends/api.py", line 1047, in open_datatree
engine = plugins.guess_engine(filename_or_obj, must_support_groups=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/simon/code/xarray/xarray/backends/plugins.py", line 212, in guess_engine
raise ValueError(error_msg)
ValueError: did not find a match in any of xarray's currently installed IO backends ['h5netcdf', 'scipy', 'netcdf4', 'pydap', 'zarr']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
https://docs.xarray.dev/en/stable/user-guide/io.htmlAnything else we need to know?
No response
Environment
Metadata
Metadata
Assignees
Labels
bugneeds triageIssue that has not been reviewed by xarray team memberIssue that has not been reviewed by xarray team member