Skip to content

Commit 520344a

Browse files
authored
chore: expunge deprecated zarr_version parameter (#3901)
* chore: expunge deprecated `zarr_version` parameter - remove `zarr_version` from functions - remove special function for handling `zarr_format` and `zarr_version` parameters - correct references in the docs to `zarr_version` - correct references in the docs to configuration for the default zarr format * docs: changelog
1 parent 2fbd30a commit 520344a

File tree

6 files changed

+15
-81
lines changed

6 files changed

+15
-81
lines changed

changes/3901.misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the deprecated `zarr_version` parameter from several functions and methods. That parameter is replaced with `zarr_format`.

docs/user-guide/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ For more information, see the
2727

2828
Configuration options include the following:
2929

30-
- Default Zarr format `default_zarr_version`
30+
- Default Zarr format `default_zarr_format`
3131
- Default array order in memory `array.order`
3232
- Whether empty chunks are written to storage `array.write_empty_chunks`
3333
- Enable experimental rectilinear chunks `array.rectilinear_chunks`

docs/user-guide/v3_migration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ The following sections provide details on breaking changes in Zarr-Python 3.
9797

9898
2. Defaulting to `zarr_format=3` - newly created arrays will use the version 3 of the
9999
Zarr specification. To continue using version 2, set `zarr_format=2` when creating arrays
100-
or set `default_zarr_version=2` in Zarr's runtime configuration.
100+
or set `default_zarr_format=2` in Zarr's runtime configuration.
101101

102102
3. Function signature change to [`zarr.Array.resize`][] - the `resize` function now takes a
103103
`zarr.core.common.ShapeLike` input rather than separate arguments for each dimension.
@@ -195,9 +195,9 @@ When installing using `pip`:
195195

196196
### Miscellaneous
197197

198-
- The keyword argument `zarr_version` available in most creation functions in `zarr`
198+
- The keyword argument `zarr_version` in most creation functions in `zarr`
199199
(e.g. [`zarr.create`][], [`zarr.open`][], [`zarr.group`][], [`zarr.array`][]) has
200-
been deprecated in favor of `zarr_format`.
200+
been removed. Use `zarr_format` instead.
201201

202202
## 🚧 Work in Progress 🚧
203203

src/zarr/api/asynchronous.py

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,6 @@ def _like_args(a: ArrayLike) -> _LikeArgs:
169169
return new
170170

171171

172-
def _handle_zarr_version_or_format(
173-
*, zarr_version: ZarrFormat | None, zarr_format: ZarrFormat | None
174-
) -> ZarrFormat | None:
175-
"""Handle the deprecated zarr_version kwarg and return zarr_format"""
176-
if zarr_format is not None and zarr_version is not None and zarr_format != zarr_version:
177-
raise ValueError(
178-
f"zarr_format {zarr_format} does not match zarr_version {zarr_version}, please only set one"
179-
)
180-
if zarr_version is not None:
181-
warnings.warn(
182-
"zarr_version is deprecated, use zarr_format", ZarrDeprecationWarning, stacklevel=2
183-
)
184-
return zarr_version
185-
return zarr_format
186-
187-
188172
async def consolidate_metadata(
189173
store: StoreLike,
190174
path: str | None = None,
@@ -289,7 +273,6 @@ async def load(
289273
store: StoreLike,
290274
path: str | None = None,
291275
zarr_format: ZarrFormat | None = None,
292-
zarr_version: ZarrFormat | None = None,
293276
) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]:
294277
"""Load data from an array or group into memory.
295278
@@ -318,7 +301,6 @@ async def load(
318301
If loading data from a group of arrays, data will not be immediately loaded into
319302
memory. Rather, arrays will be loaded into memory as they are requested.
320303
"""
321-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
322304

323305
obj = await open(store=store, path=path, zarr_format=zarr_format)
324306
if isinstance(obj, AsyncArray):
@@ -331,7 +313,6 @@ async def open(
331313
*,
332314
store: StoreLike | None = None,
333315
mode: AccessModeLiteral | None = None,
334-
zarr_version: ZarrFormat | None = None, # deprecated
335316
zarr_format: ZarrFormat | None = None,
336317
path: str | None = None,
337318
storage_options: dict[str, Any] | None = None,
@@ -367,7 +348,7 @@ async def open(
367348
z : array or group
368349
Return type depends on what exists in the given store.
369350
"""
370-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
351+
371352
if mode is None:
372353
if isinstance(store, (Store, StorePath)) and store.read_only:
373354
mode = "r"
@@ -418,7 +399,6 @@ async def open_consolidated(
418399
async def save(
419400
store: StoreLike,
420401
*args: NDArrayLike,
421-
zarr_version: ZarrFormat | None = None, # deprecated
422402
zarr_format: ZarrFormat | None = None,
423403
path: str | None = None,
424404
**kwargs: Any, # TODO: type kwargs as valid args to save
@@ -440,7 +420,6 @@ async def save(
440420
**kwargs
441421
NumPy arrays with data to save.
442422
"""
443-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
444423

445424
if len(args) == 0 and len(kwargs) == 0:
446425
raise ValueError("at least one array must be provided")
@@ -454,7 +433,6 @@ async def save_array(
454433
store: StoreLike,
455434
arr: NDArrayLike,
456435
*,
457-
zarr_version: ZarrFormat | None = None, # deprecated
458436
zarr_format: ZarrFormat | None = None,
459437
path: str | None = None,
460438
storage_options: dict[str, Any] | None = None,
@@ -482,10 +460,8 @@ async def save_array(
482460
**kwargs
483461
Passed through to [`create`][zarr.api.asynchronous.create], e.g., compressor.
484462
"""
485-
zarr_format = (
486-
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
487-
or _default_zarr_format()
488-
)
463+
if zarr_format is None:
464+
zarr_format = _default_zarr_format()
489465
if not isinstance(arr, NDArrayLike):
490466
raise TypeError("arr argument must be numpy or other NDArrayLike array")
491467

@@ -512,7 +488,6 @@ async def save_array(
512488
async def save_group(
513489
store: StoreLike,
514490
*args: NDArrayLike,
515-
zarr_version: ZarrFormat | None = None, # deprecated
516491
zarr_format: ZarrFormat | None = None,
517492
path: str | None = None,
518493
storage_options: dict[str, Any] | None = None,
@@ -542,13 +517,8 @@ async def save_group(
542517

543518
store_path = await make_store_path(store, path=path, mode="w", storage_options=storage_options)
544519

545-
zarr_format = (
546-
_handle_zarr_version_or_format(
547-
zarr_version=zarr_version,
548-
zarr_format=zarr_format,
549-
)
550-
or _default_zarr_format()
551-
)
520+
if zarr_format is None:
521+
zarr_format = _default_zarr_format()
552522

553523
for arg in args:
554524
if not isinstance(arg, NDArrayLike):
@@ -662,7 +632,6 @@ async def group(
662632
cache_attrs: bool | None = None, # not used, default changed
663633
synchronizer: Any | None = None, # not used
664634
path: str | None = None,
665-
zarr_version: ZarrFormat | None = None, # deprecated
666635
zarr_format: ZarrFormat | None = None,
667636
meta_array: Any | None = None, # not used
668637
attributes: dict[str, JSON] | None = None,
@@ -715,7 +684,6 @@ async def group(
715684
cache_attrs=cache_attrs,
716685
synchronizer=synchronizer,
717686
path=path,
718-
zarr_version=zarr_version,
719687
zarr_format=zarr_format,
720688
meta_array=meta_array,
721689
attributes=attributes,
@@ -784,7 +752,6 @@ async def open_group(
784752
path: str | None = None,
785753
chunk_store: StoreLike | None = None, # not used
786754
storage_options: dict[str, Any] | None = None,
787-
zarr_version: ZarrFormat | None = None, # deprecated
788755
zarr_format: ZarrFormat | None = None,
789756
meta_array: Any | None = None, # not used
790757
attributes: dict[str, JSON] | None = None,
@@ -846,8 +813,6 @@ async def open_group(
846813
The new group.
847814
"""
848815

849-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
850-
851816
if cache_attrs is not None:
852817
warnings.warn("cache_attrs is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
853818
if synchronizer is not None:
@@ -901,7 +866,6 @@ async def create(
901866
object_codec: Codec | None = None, # TODO: type has changed
902867
dimension_separator: Literal[".", "/"] | None = None,
903868
write_empty_chunks: bool | None = None,
904-
zarr_version: ZarrFormat | None = None, # deprecated
905869
zarr_format: ZarrFormat | None = None,
906870
meta_array: Any | None = None, # TODO: need type
907871
attributes: dict[str, JSON] | None = None,
@@ -1043,10 +1007,8 @@ async def create(
10431007
z : array
10441008
The array.
10451009
"""
1046-
zarr_format = (
1047-
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
1048-
or _default_zarr_format()
1049-
)
1010+
if zarr_format is None:
1011+
zarr_format = _default_zarr_format()
10501012

10511013
if synchronizer is not None:
10521014
warnings.warn("synchronizer is not yet implemented", ZarrRuntimeWarning, stacklevel=2)
@@ -1238,7 +1200,6 @@ async def ones_like(a: ArrayLike, **kwargs: Any) -> AnyAsyncArray:
12381200
async def open_array(
12391201
*, # note: this is a change from v2
12401202
store: StoreLike | None = None,
1241-
zarr_version: ZarrFormat | None = None, # deprecated
12421203
zarr_format: ZarrFormat | None = None,
12431204
path: PathLike = "",
12441205
storage_options: dict[str, Any] | None = None,
@@ -1252,8 +1213,6 @@ async def open_array(
12521213
StoreLike object to open. See the
12531214
[storage documentation in the user guide][user-guide-store-like]
12541215
for a description of all valid StoreLike values.
1255-
zarr_version : {2, 3, None}, optional
1256-
The zarr format to use when saving. Deprecated in favor of zarr_format.
12571216
zarr_format : {2, 3, None}, optional
12581217
The zarr format to use when saving.
12591218
path : str, optional
@@ -1273,8 +1232,6 @@ async def open_array(
12731232
mode = kwargs.pop("mode", None)
12741233
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
12751234

1276-
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
1277-
12781235
if "write_empty_chunks" in kwargs:
12791236
_warn_write_empty_chunks_kwarg()
12801237

src/zarr/api/synchronous.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def load(
140140
store: StoreLike,
141141
path: str | None = None,
142142
zarr_format: ZarrFormat | None = None,
143-
zarr_version: ZarrFormat | None = None,
144143
) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]:
145144
"""Load data from an array or group into memory.
146145
@@ -169,16 +168,13 @@ def load(
169168
If loading data from a group of arrays, data will not be immediately loaded into
170169
memory. Rather, arrays will be loaded into memory as they are requested.
171170
"""
172-
return sync(
173-
async_api.load(store=store, zarr_version=zarr_version, zarr_format=zarr_format, path=path)
174-
)
171+
return sync(async_api.load(store=store, zarr_format=zarr_format, path=path))
175172

176173

177174
def open(
178175
store: StoreLike | None = None,
179176
*,
180177
mode: AccessModeLiteral | None = None,
181-
zarr_version: ZarrFormat | None = None, # deprecated
182178
zarr_format: ZarrFormat | None = None,
183179
path: str | None = None,
184180
storage_options: dict[str, Any] | None = None,
@@ -218,7 +214,6 @@ def open(
218214
async_api.open(
219215
store=store,
220216
mode=mode,
221-
zarr_version=zarr_version,
222217
zarr_format=zarr_format,
223218
path=path,
224219
storage_options=storage_options,
@@ -243,7 +238,6 @@ def open_consolidated(*args: Any, use_consolidated: Literal[True] = True, **kwar
243238
def save(
244239
store: StoreLike,
245240
*args: NDArrayLike,
246-
zarr_version: ZarrFormat | None = None, # deprecated
247241
zarr_format: ZarrFormat | None = None,
248242
path: str | None = None,
249243
**kwargs: Any, # TODO: type kwargs as valid args to async_api.save
@@ -265,18 +259,13 @@ def save(
265259
**kwargs
266260
NumPy arrays with data to save.
267261
"""
268-
return sync(
269-
async_api.save(
270-
store, *args, zarr_version=zarr_version, zarr_format=zarr_format, path=path, **kwargs
271-
)
272-
)
262+
return sync(async_api.save(store, *args, zarr_format=zarr_format, path=path, **kwargs))
273263

274264

275265
def save_array(
276266
store: StoreLike,
277267
arr: NDArrayLike,
278268
*,
279-
zarr_version: ZarrFormat | None = None, # deprecated
280269
zarr_format: ZarrFormat | None = None,
281270
path: str | None = None,
282271
storage_options: dict[str, Any] | None = None,
@@ -309,7 +298,6 @@ def save_array(
309298
async_api.save_array(
310299
store=store,
311300
arr=arr,
312-
zarr_version=zarr_version,
313301
zarr_format=zarr_format,
314302
path=path,
315303
storage_options=storage_options,
@@ -321,7 +309,6 @@ def save_array(
321309
def save_group(
322310
store: StoreLike,
323311
*args: NDArrayLike,
324-
zarr_version: ZarrFormat | None = None, # deprecated
325312
zarr_format: ZarrFormat | None = None,
326313
path: str | None = None,
327314
storage_options: dict[str, Any] | None = None,
@@ -354,7 +341,6 @@ def save_group(
354341
async_api.save_group(
355342
store,
356343
*args,
357-
zarr_version=zarr_version,
358344
zarr_format=zarr_format,
359345
path=path,
360346
storage_options=storage_options,
@@ -416,7 +402,6 @@ def group(
416402
cache_attrs: bool | None = None, # not used, default changed
417403
synchronizer: Any | None = None, # not used
418404
path: str | None = None,
419-
zarr_version: ZarrFormat | None = None, # deprecated
420405
zarr_format: ZarrFormat | None = None,
421406
meta_array: Any | None = None, # not used
422407
attributes: dict[str, JSON] | None = None,
@@ -466,7 +451,6 @@ def group(
466451
cache_attrs=cache_attrs,
467452
synchronizer=synchronizer,
468453
path=path,
469-
zarr_version=zarr_version,
470454
zarr_format=zarr_format,
471455
meta_array=meta_array,
472456
attributes=attributes,
@@ -485,7 +469,6 @@ def open_group(
485469
path: str | None = None,
486470
chunk_store: StoreLike | None = None, # not used in async api
487471
storage_options: dict[str, Any] | None = None, # not used in async api
488-
zarr_version: ZarrFormat | None = None, # deprecated
489472
zarr_format: ZarrFormat | None = None,
490473
meta_array: Any | None = None, # not used in async api
491474
attributes: dict[str, JSON] | None = None,
@@ -556,7 +539,6 @@ def open_group(
556539
path=path,
557540
chunk_store=chunk_store,
558541
storage_options=storage_options,
559-
zarr_version=zarr_version,
560542
zarr_format=zarr_format,
561543
meta_array=meta_array,
562544
attributes=attributes,
@@ -637,7 +619,6 @@ def create(
637619
object_codec: Codec | None = None, # TODO: type has changed
638620
dimension_separator: Literal[".", "/"] | None = None,
639621
write_empty_chunks: bool | None = None, # TODO: default has changed
640-
zarr_version: ZarrFormat | None = None, # deprecated
641622
zarr_format: ZarrFormat | None = None,
642623
meta_array: Any | None = None, # TODO: need type
643624
attributes: dict[str, JSON] | None = None,
@@ -800,7 +781,6 @@ def create(
800781
object_codec=object_codec,
801782
dimension_separator=dimension_separator,
802783
write_empty_chunks=write_empty_chunks,
803-
zarr_version=zarr_version,
804784
zarr_format=zarr_format,
805785
meta_array=meta_array,
806786
attributes=attributes,
@@ -1365,7 +1345,6 @@ def ones_like(a: ArrayLike, **kwargs: Any) -> AnyArray:
13651345
def open_array(
13661346
store: StoreLike | None = None,
13671347
*,
1368-
zarr_version: ZarrFormat | None = None,
13691348
zarr_format: ZarrFormat | None = None,
13701349
path: PathLike = "",
13711350
storage_options: dict[str, Any] | None = None,
@@ -1379,8 +1358,6 @@ def open_array(
13791358
StoreLike object to open. See the
13801359
[storage documentation in the user guide][user-guide-store-like]
13811360
for a description of all valid StoreLike values.
1382-
zarr_version : {2, 3, None}, optional
1383-
The zarr format to use when saving. Deprecated in favor of zarr_format.
13841361
zarr_format : {2, 3, None}, optional
13851362
The zarr format to use when saving.
13861363
path : str, optional
@@ -1401,7 +1378,6 @@ def open_array(
14011378
sync(
14021379
async_api.open_array(
14031380
store=store,
1404-
zarr_version=zarr_version,
14051381
zarr_format=zarr_format,
14061382
path=path,
14071383
storage_options=storage_options,

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _warn_order_kwarg() -> None:
240240

241241

242242
def _default_zarr_format() -> ZarrFormat:
243-
"""Return the default zarr_version"""
243+
"""Return the default zarr_format."""
244244
return cast("ZarrFormat", int(zarr_config.get("default_zarr_format", 3)))
245245

246246

0 commit comments

Comments
 (0)