Skip to content

Commit 60e3560

Browse files
committed
set convenience routines default to zarr_version=None
This will infer the version from the store if it is a BaseStore. Otherwise it will use 2 for backwards compatibility
1 parent 2552c22 commit 60e3560

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

zarr/convenience.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _check_and_update_path(store: BaseStore, path):
2828

2929

3030
# noinspection PyShadowingBuiltins
31-
def open(store: StoreLike = None, mode: str = "a", *, zarr_version=2, path=None, **kwargs):
31+
def open(store: StoreLike = None, mode: str = "a", *, zarr_version=None, path=None, **kwargs):
3232
"""Convenience function to open a group or array using file-mode-like semantics.
3333
3434
Parameters
@@ -40,9 +40,11 @@ def open(store: StoreLike = None, mode: str = "a", *, zarr_version=2, path=None,
4040
read/write (must exist); 'a' means read/write (create if doesn't
4141
exist); 'w' means create (overwrite if exists); 'w-' means create
4242
(fail if exists).
43-
zarr_version : {2, 3}
44-
The zarr protocol version to use.
45-
path : str
43+
zarr_version : {2, 3, None}, optional
44+
The zarr protocol version to use. The default value of None will attempt
45+
to infer the version from `store` if possible, otherwise it will fall
46+
back to 2.
47+
path : str or None, optional
4648
The path within the store to open.
4749
**kwargs
4850
Additional parameters are passed through to :func:`zarr.creation.open_array` or
@@ -93,7 +95,8 @@ def open(store: StoreLike = None, mode: str = "a", *, zarr_version=2, path=None,
9395
store, clobber=clobber, storage_options=kwargs.pop("storage_options", {}),
9496
zarr_version=zarr_version,
9597
)
96-
path = _check_and_update_path(_store, path)
98+
# path = _check_and_update_path(_store, path)
99+
path = normalize_storage_path(path)
97100
kwargs['path'] = path
98101

99102
if mode in {'w', 'w-', 'x'}:
@@ -121,7 +124,7 @@ def _might_close(path):
121124
return isinstance(path, (str, os.PathLike))
122125

123126

124-
def save_array(store: StoreLike, arr, *, zarr_version=2, path=None, **kwargs):
127+
def save_array(store: StoreLike, arr, *, zarr_version=None, path=None, **kwargs):
125128
"""Convenience function to save a NumPy array to the local file system, following a
126129
similar API to the NumPy save() function.
127130
@@ -131,9 +134,11 @@ def save_array(store: StoreLike, arr, *, zarr_version=2, path=None, **kwargs):
131134
Store or path to directory in file system or name of zip file.
132135
arr : ndarray
133136
NumPy array with data to save.
134-
zarr_version : {2, 3}
135-
The zarr protocol version to use when saving.
136-
path : str
137+
zarr_version : {2, 3, None}, optional
138+
The zarr protocol version to use when saving. The default value of None
139+
will attempt to infer the version from `store` if possible, otherwise
140+
it will fall back to 2.
141+
path : str or None, optional
137142
The path within the store where the array will be saved.
138143
kwargs
139144
Passed through to :func:`create`, e.g., compressor.
@@ -168,7 +173,7 @@ def save_array(store: StoreLike, arr, *, zarr_version=2, path=None, **kwargs):
168173
_store.close()
169174

170175

171-
def save_group(store: StoreLike, *args, zarr_version=2, path=None, **kwargs):
176+
def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
172177
"""Convenience function to save several NumPy arrays to the local file system, following a
173178
similar API to the NumPy savez()/savez_compressed() functions.
174179
@@ -178,9 +183,11 @@ def save_group(store: StoreLike, *args, zarr_version=2, path=None, **kwargs):
178183
Store or path to directory in file system or name of zip file.
179184
args : ndarray
180185
NumPy arrays with data to save.
181-
zarr_version : {2, 3}
182-
The zarr protocol version to use when saving.
183-
path : str
186+
zarr_version : {2, 3, None}, optional
187+
The zarr protocol version to use when saving. The default value of None
188+
will attempt to infer the version from `store` if possible, otherwise
189+
it will fall back to 2.
190+
path : str or None, optional
184191
Path within the store where the group will be saved.
185192
kwargs
186193
NumPy arrays with data to save.
@@ -249,7 +256,7 @@ def save_group(store: StoreLike, *args, zarr_version=2, path=None, **kwargs):
249256
_store.close()
250257

251258

252-
def save(store: StoreLike, *args, zarr_version=2, path=None, **kwargs):
259+
def save(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
253260
"""Convenience function to save an array or group of arrays to the local file system.
254261
255262
Parameters
@@ -258,9 +265,11 @@ def save(store: StoreLike, *args, zarr_version=2, path=None, **kwargs):
258265
Store or path to directory in file system or name of zip file.
259266
args : ndarray
260267
NumPy arrays with data to save.
261-
zarr_version : {2, 3}
262-
The zarr protocol version to use when saving.
263-
path : str
268+
zarr_version : {2, 3, None}, optional
269+
The zarr protocol version to use when saving. The default value of None
270+
will attempt to infer the version from `store` if possible, otherwise
271+
it will fall back to 2.
272+
path : str or None, optional
264273
The path within the group where the arrays will be saved.
265274
kwargs
266275
NumPy arrays with data to save.
@@ -364,13 +373,19 @@ def __repr__(self):
364373
return r
365374

366375

367-
def load(store: StoreLike, zarr_version=2, path=None):
376+
def load(store: StoreLike, zarr_version=None, path=None):
368377
"""Load data from an array or group into memory.
369378
370379
Parameters
371380
----------
372381
store : MutableMapping or string
373382
Store or path to directory in file system or name of zip file.
383+
zarr_version : {2, 3, None}, optional
384+
The zarr protocol version to use when loading. The default value of
385+
None will attempt to infer the version from `store` if possible,
386+
otherwise it will fall back to 2.
387+
path : str or None, optional
388+
The path within the store from which to load.
374389
375390
Returns
376391
-------

0 commit comments

Comments
 (0)