Skip to content

Commit ca87f1b

Browse files
committed
Merge branch 'main' into eval
2 parents 79fc511 + 18ebe98 commit ca87f1b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ New Features
2828
Breaking Changes
2929
~~~~~~~~~~~~~~~~
3030

31+
- Change the default value for ``chunk`` in ``open_zarr`` to ``_default`` and remove special mapping of ``"auto"``
32+
to ``{}`` or ``None`` in ``open_zarr``. If ``chunks`` is not set, the default behavior is the same as before.
33+
Explicitly setting ``chunks="auto"`` will match the behavior of ``chunks="auto"`` in
34+
``open_dataset(..., engine="zarr")`` (:issue:`11002` :pull:`11010`).
35+
By `Julia Signell <https://github.com/jsignell>`_.
3136
- :py:meth:`Dataset.identical`,` :py:meth:`DataArray.identical`, and
3237
:py:func:`testings.assert_identical` now compare indexes (xindexes).
3338
Two objects with identical data but different indexes will no longer

xarray/backends/zarr.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from xarray.core.utils import (
3131
FrozenDict,
3232
HiddenKeyDict,
33+
_default,
3334
attempt_import,
3435
close_on_error,
3536
emit_user_level_warning,
@@ -1400,7 +1401,7 @@ def open_zarr(
14001401
store,
14011402
group=None,
14021403
synchronizer=None,
1403-
chunks="auto",
1404+
chunks=_default,
14041405
decode_cf=True,
14051406
mask_and_scale=True,
14061407
decode_times=True,
@@ -1436,8 +1437,9 @@ def open_zarr(
14361437
Array synchronizer provided to zarr
14371438
group : str, optional
14381439
Group path. (a.k.a. `path` in zarr terminology.)
1439-
chunks : int, dict, 'auto' or None, default: 'auto'
1440-
If provided, used to load the data into dask arrays.
1440+
chunks : int, dict, "auto" or None, optional
1441+
Used to load the data into dask arrays. Default behavior is to use
1442+
``chunks={}`` if dask is available, otherwise ``chunks=None``.
14411443
14421444
- ``chunks='auto'`` will use dask ``auto`` chunking taking into account the
14431445
engine preferred chunks.
@@ -1558,7 +1560,7 @@ def open_zarr(
15581560
if from_array_kwargs is None:
15591561
from_array_kwargs = {}
15601562

1561-
if chunks == "auto":
1563+
if chunks is _default:
15621564
try:
15631565
guess_chunkmanager(
15641566
chunked_array_type

xarray/tests/test_backends.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,18 @@ def test_chunk_encoding_with_larger_dask_chunks(self) -> None:
36373637
) as ds1:
36383638
assert_equal(ds1, original)
36393639

3640+
@requires_dask
3641+
def test_chunk_auto_with_small_dask_chunks(self) -> None:
3642+
original = Dataset({"u": (("x",), np.zeros(10))}).chunk({"x": 2})
3643+
with self.create_zarr_target() as store:
3644+
original.to_zarr(store, **self.version_kwargs)
3645+
with xr.open_zarr(store, **self.version_kwargs) as default:
3646+
assert default.chunks == {"x": (2, 2, 2, 2, 2)}
3647+
with xr.open_zarr(store, chunks="auto", **self.version_kwargs) as auto:
3648+
assert_identical(auto, original)
3649+
assert auto.chunks == {"x": (10,)}
3650+
assert auto.chunks != default.chunks
3651+
36403652
@requires_cftime
36413653
def test_open_zarr_use_cftime(self) -> None:
36423654
ds = create_test_data()

0 commit comments

Comments
 (0)