From a26554483ce89c8c3976434ab4f757f420932dc0 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Thu, 2 Oct 2025 11:28:54 +0200 Subject: [PATCH 1/3] Add supports_groups=True to Zarr backend --- xarray/backends/zarr.py | 1 + 1 file changed, 1 insertion(+) 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): From 48fd1ee78e8770589ee7d3de9259a59721d30fdb Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Thu, 2 Oct 2025 11:34:50 +0200 Subject: [PATCH 2/3] Add test case --- xarray/tests/test_backends_datatree.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xarray/tests/test_backends_datatree.py b/xarray/tests/test_backends_datatree.py index 5b2b93f9ade..e562b172412 100644 --- a/xarray/tests/test_backends_datatree.py +++ b/xarray/tests/test_backends_datatree.py @@ -1089,3 +1089,23 @@ 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.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) From f41cb19a40fdbb30de38eb356f968f1e23d946a1 Mon Sep 17 00:00:00 2001 From: Simon Perkins Date: Fri, 3 Oct 2025 19:57:27 +0200 Subject: [PATCH 3/3] xfail test_zarr_engine_recognised on windows --- xarray/tests/test_backends_datatree.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xarray/tests/test_backends_datatree.py b/xarray/tests/test_backends_datatree.py index e562b172412..6b15e74c2e9 100644 --- a/xarray/tests/test_backends_datatree.py +++ b/xarray/tests/test_backends_datatree.py @@ -1090,6 +1090,10 @@ def test_write_inherited_coords_true(self, tmpdir, zarr_format) -> 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" )