Skip to content

Commit 348aed8

Browse files
committed
Merge remote-tracking branch 'upstream/v3' into user/tom/fix/v2-compat
2 parents b13dee3 + c878da2 commit 348aed8

File tree

11 files changed

+590
-302
lines changed

11 files changed

+590
-302
lines changed

src/zarr/api/asynchronous.py

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ async def open(
194194
zarr_version: ZarrFormat | None = None, # deprecated
195195
zarr_format: ZarrFormat | None = None,
196196
path: str | None = None,
197+
storage_options: dict[str, Any] | None = None,
197198
**kwargs: Any, # TODO: type kwargs as valid args to open_array
198199
) -> AsyncArray | AsyncGroup:
199200
"""Convenience function to open a group or array using file-mode-like semantics.
@@ -211,6 +212,9 @@ async def open(
211212
The zarr format to use when saving.
212213
path : str or None, optional
213214
The path within the store to open.
215+
storage_options : dict
216+
If using an fsspec URL to create the store, these will be passed to
217+
the backend implementation. Ignored otherwise.
214218
**kwargs
215219
Additional parameters are passed through to :func:`zarr.creation.open_array` or
216220
:func:`zarr.hierarchy.open_group`.
@@ -221,7 +225,7 @@ async def open(
221225
Return type depends on what exists in the given store.
222226
"""
223227
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
224-
store_path = await make_store_path(store, mode=mode)
228+
store_path = await make_store_path(store, mode=mode, storage_options=storage_options)
225229

226230
if path is not None:
227231
store_path = store_path / path
@@ -276,6 +280,7 @@ async def save_array(
276280
zarr_version: ZarrFormat | None = None, # deprecated
277281
zarr_format: ZarrFormat | None = None,
278282
path: str | None = None,
283+
storage_options: dict[str, Any] | None = None,
279284
**kwargs: Any, # TODO: type kwargs as valid args to create
280285
) -> None:
281286
"""Convenience function to save a NumPy array to the local file system, following a
@@ -291,6 +296,9 @@ async def save_array(
291296
The zarr format to use when saving.
292297
path : str or None, optional
293298
The path within the store where the array will be saved.
299+
storage_options : dict
300+
If using an fsspec URL to create the store, these will be passed to
301+
the backend implementation. Ignored otherwise.
294302
kwargs
295303
Passed through to :func:`create`, e.g., compressor.
296304
"""
@@ -299,7 +307,7 @@ async def save_array(
299307
or _default_zarr_version()
300308
)
301309

302-
store_path = await make_store_path(store, mode="w")
310+
store_path = await make_store_path(store, mode="w", storage_options=storage_options)
303311
if path is not None:
304312
store_path = store_path / path
305313
new = await AsyncArray.create(
@@ -319,6 +327,7 @@ async def save_group(
319327
zarr_version: ZarrFormat | None = None, # deprecated
320328
zarr_format: ZarrFormat | None = None,
321329
path: str | None = None,
330+
storage_options: dict[str, Any] | None = None,
322331
**kwargs: NDArrayLike,
323332
) -> None:
324333
"""Convenience function to save several NumPy arrays to the local file system, following a
@@ -334,22 +343,40 @@ async def save_group(
334343
The zarr format to use when saving.
335344
path : str or None, optional
336345
Path within the store where the group will be saved.
346+
storage_options : dict
347+
If using an fsspec URL to create the store, these will be passed to
348+
the backend implementation. Ignored otherwise.
337349
kwargs
338350
NumPy arrays with data to save.
339351
"""
340352
zarr_format = (
341-
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
353+
_handle_zarr_version_or_format(
354+
zarr_version=zarr_version,
355+
zarr_format=zarr_format,
356+
)
342357
or _default_zarr_version()
343358
)
344359

345360
if len(args) == 0 and len(kwargs) == 0:
346361
raise ValueError("at least one array must be provided")
347362
aws = []
348363
for i, arr in enumerate(args):
349-
aws.append(save_array(store, arr, zarr_format=zarr_format, path=f"{path}/arr_{i}"))
364+
aws.append(
365+
save_array(
366+
store,
367+
arr,
368+
zarr_format=zarr_format,
369+
path=f"{path}/arr_{i}",
370+
storage_options=storage_options,
371+
)
372+
)
350373
for k, arr in kwargs.items():
351374
_path = f"{path}/{k}" if path is not None else k
352-
aws.append(save_array(store, arr, zarr_format=zarr_format, path=_path))
375+
aws.append(
376+
save_array(
377+
store, arr, zarr_format=zarr_format, path=_path, storage_options=storage_options
378+
)
379+
)
353380
await asyncio.gather(*aws)
354381

355382

@@ -418,6 +445,7 @@ async def group(
418445
zarr_format: ZarrFormat | None = None,
419446
meta_array: Any | None = None, # not used
420447
attributes: dict[str, JSON] | None = None,
448+
storage_options: dict[str, Any] | None = None,
421449
) -> AsyncGroup:
422450
"""Create a group.
423451
@@ -444,6 +472,9 @@ async def group(
444472
to users. Use `numpy.empty(())` by default.
445473
zarr_format : {2, 3, None}, optional
446474
The zarr format to use when saving.
475+
storage_options : dict
476+
If using an fsspec URL to create the store, these will be passed to
477+
the backend implementation. Ignored otherwise.
447478
448479
Returns
449480
-------
@@ -453,7 +484,7 @@ async def group(
453484

454485
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
455486

456-
store_path = await make_store_path(store)
487+
store_path = await make_store_path(store, storage_options=storage_options)
457488
if path is not None:
458489
store_path = store_path / path
459490

@@ -488,7 +519,7 @@ async def open_group(
488519
synchronizer: Any = None, # not used
489520
path: str | None = None,
490521
chunk_store: StoreLike | None = None, # not used
491-
storage_options: dict[str, Any] | None = None, # not used
522+
storage_options: dict[str, Any] | None = None,
492523
zarr_version: ZarrFormat | None = None, # deprecated
493524
zarr_format: ZarrFormat | None = None,
494525
meta_array: Any | None = None, # not used
@@ -548,10 +579,8 @@ async def open_group(
548579
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
549580
if chunk_store is not None:
550581
warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2)
551-
if storage_options is not None:
552-
warnings.warn("storage_options is not yet implemented", RuntimeWarning, stacklevel=2)
553582

554-
store_path = await make_store_path(store, mode=mode)
583+
store_path = await make_store_path(store, mode=mode, storage_options=storage_options)
555584
if path is not None:
556585
store_path = store_path / path
557586

@@ -575,7 +604,7 @@ async def create(
575604
chunks: ChunkCoords | None = None, # TODO: v2 allowed chunks=True
576605
dtype: npt.DTypeLike | None = None,
577606
compressor: dict[str, JSON] | None = None, # TODO: default and type change
578-
fill_value: Any = 0, # TODO: need type
607+
fill_value: Any | None = 0, # TODO: need type
579608
order: MemoryOrder | None = None, # TODO: default change
580609
store: str | StoreLike | None = None,
581610
synchronizer: Any | None = None,
@@ -603,6 +632,7 @@ async def create(
603632
) = None,
604633
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
605634
dimension_names: Iterable[str] | None = None,
635+
storage_options: dict[str, Any] | None = None,
606636
**kwargs: Any,
607637
) -> AsyncArray:
608638
"""Create an array.
@@ -674,6 +704,9 @@ async def create(
674704
to users. Use `numpy.empty(())` by default.
675705
676706
.. versionadded:: 2.13
707+
storage_options : dict
708+
If using an fsspec URL to create the store, these will be passed to
709+
the backend implementation. Ignored otherwise.
677710
678711
Returns
679712
-------
@@ -725,7 +758,7 @@ async def create(
725758
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
726759

727760
mode = kwargs.pop("mode", cast(AccessModeLiteral, "r" if read_only else "w"))
728-
store_path = await make_store_path(store, mode=mode)
761+
store_path = await make_store_path(store, mode=mode, storage_options=storage_options)
729762
if path is not None:
730763
store_path = store_path / path
731764

@@ -827,7 +860,7 @@ async def full_like(a: ArrayLike, **kwargs: Any) -> AsyncArray:
827860
"""
828861
like_kwargs = _like_args(a, kwargs)
829862
if isinstance(a, AsyncArray):
830-
kwargs.setdefault("fill_value", a.metadata.fill_value)
863+
like_kwargs.setdefault("fill_value", a.metadata.fill_value)
831864
return await full(**like_kwargs)
832865

833866

@@ -875,6 +908,7 @@ async def open_array(
875908
zarr_version: ZarrFormat | None = None, # deprecated
876909
zarr_format: ZarrFormat | None = None,
877910
path: PathLike | None = None,
911+
storage_options: dict[str, Any] | None = None,
878912
**kwargs: Any, # TODO: type kwargs as valid args to save
879913
) -> AsyncArray:
880914
"""Open an array using file-mode-like semantics.
@@ -887,6 +921,9 @@ async def open_array(
887921
The zarr format to use when saving.
888922
path : string, optional
889923
Path in store to array.
924+
storage_options : dict
925+
If using an fsspec URL to create the store, these will be passed to
926+
the backend implementation. Ignored otherwise.
890927
**kwargs
891928
Any keyword arguments to pass to the array constructor.
892929
@@ -896,7 +933,7 @@ async def open_array(
896933
The opened array.
897934
"""
898935

899-
store_path = await make_store_path(store)
936+
store_path = await make_store_path(store, storage_options=storage_options)
900937
if path is not None:
901938
store_path = store_path / path
902939

src/zarr/api/synchronous.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def save_group(
137137
zarr_version: ZarrFormat | None = None, # deprecated
138138
zarr_format: ZarrFormat | None = None,
139139
path: str | None = None,
140+
storage_options: dict[str, Any] | None = None,
140141
**kwargs: NDArrayLike,
141142
) -> None:
142143
return sync(
@@ -146,6 +147,7 @@ def save_group(
146147
zarr_version=zarr_version,
147148
zarr_format=zarr_format,
148149
path=path,
150+
storage_options=storage_options,
149151
**kwargs,
150152
)
151153
)

0 commit comments

Comments
 (0)