diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index ac614e9e7cd..ca89d9435f9 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1620,6 +1620,7 @@ class ZarrBackendEntrypoint(BackendEntrypoint): description = "Open zarr files (.zarr) using zarr in Xarray" url = "https://docs.xarray.dev/en/stable/generated/xarray.backends.ZarrBackendEntrypoint.html" + supports_groups = True def guess_can_open(self, filename_or_obj: T_PathFileOrDataStore) -> bool: if isinstance(filename_or_obj, str | os.PathLike): diff --git a/xarray/tests/test_backends_datatree.py b/xarray/tests/test_backends_datatree.py index 5b2b93f9ade..6b15e74c2e9 100644 --- a/xarray/tests/test_backends_datatree.py +++ b/xarray/tests/test_backends_datatree.py @@ -1089,3 +1089,27 @@ def test_write_inherited_coords_true(self, tmpdir, zarr_format) -> None: expected_child.name = None with open_datatree(filepath, group="child", engine="zarr") as roundtrip_child: assert_identical(expected_child, roundtrip_child) + + @pytest.mark.xfail( + ON_WINDOWS, + reason="Permission errors from Zarr: https://github.com/pydata/xarray/pull/10793", + ) + @pytest.mark.filterwarnings( + "ignore:Failed to open Zarr store with consolidated metadata:RuntimeWarning" + ) + def test_zarr_engine_recognised(self, tmpdir, zarr_format) -> None: + """Test that xarray can guess the zarr backend when the engine is not specified""" + original_dt = DataTree.from_dict( + { + "/": xr.Dataset(coords={"x": [1, 2, 3]}), + "/child": xr.Dataset({"foo": ("x", [4, 5, 6])}), + } + ) + + filepath = str(tmpdir / "test.zarr") + original_dt.to_zarr( + filepath, write_inherited_coords=True, zarr_format=zarr_format + ) + + with open_datatree(filepath) as roundtrip_dt: + assert_identical(original_dt, roundtrip_dt)