diff --git a/doc/whats-new.rst b/doc/whats-new.rst index a49564649cf..dd141d4bf5a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -28,6 +28,11 @@ New Features Breaking Changes ~~~~~~~~~~~~~~~~ +- 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 `_. - :py:meth:`Dataset.identical`,` :py:meth:`DataArray.identical`, and :py:func:`testings.assert_identical` now compare indexes (xindexes). Two objects with identical data but different indexes will no longer diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index fe004c212b6..410a6a49a7b 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, optional + 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,7 +1560,7 @@ 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 diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 1593b56355e..b5161fcf7b3 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, **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: ds = create_test_data()