Skip to content

Commit fd7c765

Browse files
authored
Update DataArray.to_zarr to match Dataset.to_zarr. (#10164)
1 parent cdebbf5 commit fd7c765

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Deprecations
3737
Bug fixes
3838
~~~~~~~~~
3939

40+
- Update the parameters of :py:meth:`~xarray.DataArray.to_zarr` to match :py:meth:`~xarray.Dataset.to_zarr`.
41+
This fixes the issue where using the ``zarr_version`` parameter would raise a deprecation warning telling the user to use
42+
a non-existent ``zarr_format`` parameter instead. (:issue:`10163`, :pull:`10164`)
43+
By `Karl Krauth <https://github.com/Karl-Krauth>`_.
4044

4145
Documentation
4246
~~~~~~~~~~~~~

xarray/core/dataarray.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,6 +4242,9 @@ def to_zarr(
42424242
safe_chunks: bool = True,
42434243
storage_options: dict[str, str] | None = None,
42444244
zarr_version: int | None = None,
4245+
zarr_format: int | None = None,
4246+
write_empty_chunks: bool | None = None,
4247+
chunkmanager_store_kwargs: dict[str, Any] | None = None,
42454248
) -> ZarrStore: ...
42464249

42474250
# compute=False returns dask.Delayed
@@ -4262,6 +4265,9 @@ def to_zarr(
42624265
safe_chunks: bool = True,
42634266
storage_options: dict[str, str] | None = None,
42644267
zarr_version: int | None = None,
4268+
zarr_format: int | None = None,
4269+
write_empty_chunks: bool | None = None,
4270+
chunkmanager_store_kwargs: dict[str, Any] | None = None,
42654271
) -> Delayed: ...
42664272

42674273
def to_zarr(
@@ -4280,6 +4286,9 @@ def to_zarr(
42804286
safe_chunks: bool = True,
42814287
storage_options: dict[str, str] | None = None,
42824288
zarr_version: int | None = None,
4289+
zarr_format: int | None = None,
4290+
write_empty_chunks: bool | None = None,
4291+
chunkmanager_store_kwargs: dict[str, Any] | None = None,
42834292
) -> ZarrStore | Delayed:
42844293
"""Write DataArray contents to a Zarr store
42854294
@@ -4380,9 +4389,30 @@ def to_zarr(
43804389
Any additional parameters for the storage backend (ignored for local
43814390
paths).
43824391
zarr_version : int or None, optional
4383-
The desired zarr spec version to target (currently 2 or 3). The
4384-
default of None will attempt to determine the zarr version from
4385-
``store`` when possible, otherwise defaulting to 2.
4392+
4393+
.. deprecated:: 2024.9.1
4394+
Use ``zarr_format`` instead.
4395+
4396+
zarr_format : int or None, optional
4397+
The desired zarr format to target (currently 2 or 3). The default
4398+
of None will attempt to determine the zarr version from ``store`` when
4399+
possible, otherwise defaulting to the default version used by
4400+
the zarr-python library installed.
4401+
write_empty_chunks : bool or None, optional
4402+
If True, all chunks will be stored regardless of their
4403+
contents. If False, each chunk is compared to the array's fill value
4404+
prior to storing. If a chunk is uniformly equal to the fill value, then
4405+
that chunk is not be stored, and the store entry for that chunk's key
4406+
is deleted. This setting enables sparser storage, as only chunks with
4407+
non-fill-value data are stored, at the expense of overhead associated
4408+
with checking the data of each chunk. If None (default) fall back to
4409+
specification(s) in ``encoding`` or Zarr defaults. A ``ValueError``
4410+
will be raised if the value of this (if not None) differs with
4411+
``encoding``.
4412+
chunkmanager_store_kwargs : dict, optional
4413+
Additional keyword arguments passed on to the `ChunkManager.store` method used to store
4414+
chunked arrays. For example for a dask array additional kwargs will be passed eventually to
4415+
:py:func:`dask.array.store()`. Experimental API that should not be relied upon.
43864416
43874417
Returns
43884418
-------
@@ -4448,6 +4478,9 @@ def to_zarr(
44484478
safe_chunks=safe_chunks,
44494479
storage_options=storage_options,
44504480
zarr_version=zarr_version,
4481+
zarr_format=zarr_format,
4482+
write_empty_chunks=write_empty_chunks,
4483+
chunkmanager_store_kwargs=chunkmanager_store_kwargs,
44514484
)
44524485

44534486
def to_dict(

0 commit comments

Comments
 (0)