From e7015da6138876d862c90d1bf9568c4c27b0e54c Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Fri, 12 Dec 2025 12:13:09 -0500 Subject: [PATCH 1/5] Remove special mapping of `auto` to {} in `open_zarr` --- xarray/backends/zarr.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index fe004c212b6..554d82c8af2 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1564,7 +1564,6 @@ def open_zarr( chunked_array_type ) # attempt to import that parallel backend - chunks = {} except (ValueError, ImportError): chunks = None From 77c118983f1fde88408418bb4719739a5d984de4 Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Fri, 12 Dec 2025 13:57:48 -0500 Subject: [PATCH 2/5] Add test to prove that auto can differe from on-disk --- xarray/tests/test_backends.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 5aab153117d..57ae3c51de2 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -3637,6 +3637,18 @@ def test_chunk_encoding_with_larger_dask_chunks(self) -> None: ) as ds1: assert_equal(ds1, original) + @requires_dask + def test_chunk_auto_with_small_dask_chunks(self) -> None: + original = Dataset({"u": (("x",), np.zeros(10))}).chunk({"x": 2}) + with self.create_zarr_target() as store: + original.to_zarr(store, **self.version_kwargs) + with xr.open_zarr(store, chunks={}, **self.version_kwargs) as native: + assert native.chunks == {"x": (2, 2, 2, 2, 2)} + with xr.open_zarr(store, **self.version_kwargs) as actual: + assert_identical(actual, original) + assert actual.chunks == {"x": (10,)} + assert actual.chunks != native.chunks + @requires_cftime def test_open_zarr_use_cftime(self) -> None: ds = create_test_data() From 797f1b4ce66f0668d6eb7ae7cedbbdbdde894b38 Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Fri, 12 Dec 2025 14:09:37 -0500 Subject: [PATCH 3/5] Update what's new --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 7e3badc7143..257aee5d075 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -18,6 +18,9 @@ New Features Breaking Changes ~~~~~~~~~~~~~~~~ +- Remove special mapping of ``"auto"`` to ``{}`` in ``open_zarr``. This matches the behavior of ``open_dataset(..., engine="zarr")`` + and means that by default the chunks might be a multiple of the the on-disk chunks. (:issue:`11002` :pull:`11010`). + By `Julia Signell `_. Deprecations ~~~~~~~~~~~~ From 01550f6d1a9e35511e580208909a4e6de55c8b8e Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Wed, 17 Dec 2025 13:49:34 -0500 Subject: [PATCH 4/5] Keep default the same, change what ``chunks='auto'`` means --- doc/whats-new.rst | 6 ++++-- xarray/backends/zarr.py | 11 +++++++---- xarray/tests/test_backends.py | 12 ++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 257aee5d075..8af499e07f8 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -18,8 +18,10 @@ New Features Breaking Changes ~~~~~~~~~~~~~~~~ -- Remove special mapping of ``"auto"`` to ``{}`` in ``open_zarr``. This matches the behavior of ``open_dataset(..., engine="zarr")`` - and means that by default the chunks might be a multiple of the the on-disk chunks. (:issue:`11002` :pull:`11010`). +- Change the default value for ``chunk`` in ``open_zarr`` to ``_default`` and remove special mapping of ``"auto"`` + to ``{}`` or ``None`` in ``open_zarr``. If ``chunks`` is not set, the default behavior is the same as before. + Explicitly setting ``chunks="auto"`` will match the behavior of ``chunks="auto"`` in + ``open_dataset(..., engine="zarr")`` (:issue:`11002` :pull:`11010`). By `Julia Signell `_. Deprecations diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 554d82c8af2..b7e69ec73b4 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -30,6 +30,7 @@ from xarray.core.utils import ( FrozenDict, HiddenKeyDict, + _default, attempt_import, close_on_error, emit_user_level_warning, @@ -1400,7 +1401,7 @@ def open_zarr( store, group=None, synchronizer=None, - chunks="auto", + chunks=_default, decode_cf=True, mask_and_scale=True, decode_times=True, @@ -1436,8 +1437,9 @@ def open_zarr( Array synchronizer provided to zarr group : str, optional Group path. (a.k.a. `path` in zarr terminology.) - chunks : int, dict, 'auto' or None, default: 'auto' - If provided, used to load the data into dask arrays. + chunks : int, dict, 'auto' or None, default: {} or None + Used to load the data into dask arrays. Default behavior is to use + ``chunks={}`` if dask is available, otherwise ``chunks=None``. - ``chunks='auto'`` will use dask ``auto`` chunking taking into account the engine preferred chunks. @@ -1558,12 +1560,13 @@ def open_zarr( if from_array_kwargs is None: from_array_kwargs = {} - if chunks == "auto": + if chunks is _default: try: guess_chunkmanager( chunked_array_type ) # attempt to import that parallel backend + chunks = {} except (ValueError, ImportError): chunks = None diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 57ae3c51de2..4fc446fd2ad 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -3642,12 +3642,12 @@ def test_chunk_auto_with_small_dask_chunks(self) -> None: original = Dataset({"u": (("x",), np.zeros(10))}).chunk({"x": 2}) with self.create_zarr_target() as store: original.to_zarr(store, **self.version_kwargs) - with xr.open_zarr(store, chunks={}, **self.version_kwargs) as native: - assert native.chunks == {"x": (2, 2, 2, 2, 2)} - with xr.open_zarr(store, **self.version_kwargs) as actual: - assert_identical(actual, original) - assert actual.chunks == {"x": (10,)} - assert actual.chunks != native.chunks + with xr.open_zarr(store, **self.version_kwargs) as default: + assert default.chunks == {"x": (2, 2, 2, 2, 2)} + with xr.open_zarr(store, chunks="auto", **self.version_kwargs) as auto: + assert_identical(auto, original) + assert auto.chunks == {"x": (10,)} + assert auto.chunks != default.chunks @requires_cftime def test_open_zarr_use_cftime(self) -> None: From 0494e7f1645aa50994781e9be4013e4b6b78a93d Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Wed, 17 Dec 2025 14:19:42 -0500 Subject: [PATCH 5/5] Update docstring Co-authored-by: Justus Magin --- xarray/backends/zarr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index b7e69ec73b4..410a6a49a7b 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1437,7 +1437,7 @@ def open_zarr( Array synchronizer provided to zarr group : str, optional Group path. (a.k.a. `path` in zarr terminology.) - chunks : int, dict, 'auto' or None, default: {} or None + chunks : int, dict, "auto" or None, optional Used to load the data into dask arrays. Default behavior is to use ``chunks={}`` if dask is available, otherwise ``chunks=None``.