@@ -194,6 +194,7 @@ async def open(
194
194
zarr_version : ZarrFormat | None = None , # deprecated
195
195
zarr_format : ZarrFormat | None = None ,
196
196
path : str | None = None ,
197
+ storage_options : dict [str , Any ] | None = None ,
197
198
** kwargs : Any , # TODO: type kwargs as valid args to open_array
198
199
) -> AsyncArray | AsyncGroup :
199
200
"""Convenience function to open a group or array using file-mode-like semantics.
@@ -211,6 +212,9 @@ async def open(
211
212
The zarr format to use when saving.
212
213
path : str or None, optional
213
214
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.
214
218
**kwargs
215
219
Additional parameters are passed through to :func:`zarr.creation.open_array` or
216
220
:func:`zarr.hierarchy.open_group`.
@@ -221,7 +225,7 @@ async def open(
221
225
Return type depends on what exists in the given store.
222
226
"""
223
227
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 )
225
229
226
230
if path is not None :
227
231
store_path = store_path / path
@@ -276,6 +280,7 @@ async def save_array(
276
280
zarr_version : ZarrFormat | None = None , # deprecated
277
281
zarr_format : ZarrFormat | None = None ,
278
282
path : str | None = None ,
283
+ storage_options : dict [str , Any ] | None = None ,
279
284
** kwargs : Any , # TODO: type kwargs as valid args to create
280
285
) -> None :
281
286
"""Convenience function to save a NumPy array to the local file system, following a
@@ -291,6 +296,9 @@ async def save_array(
291
296
The zarr format to use when saving.
292
297
path : str or None, optional
293
298
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.
294
302
kwargs
295
303
Passed through to :func:`create`, e.g., compressor.
296
304
"""
@@ -299,7 +307,7 @@ async def save_array(
299
307
or _default_zarr_version ()
300
308
)
301
309
302
- store_path = await make_store_path (store , mode = "w" )
310
+ store_path = await make_store_path (store , mode = "w" , storage_options = storage_options )
303
311
if path is not None :
304
312
store_path = store_path / path
305
313
new = await AsyncArray .create (
@@ -319,6 +327,7 @@ async def save_group(
319
327
zarr_version : ZarrFormat | None = None , # deprecated
320
328
zarr_format : ZarrFormat | None = None ,
321
329
path : str | None = None ,
330
+ storage_options : dict [str , Any ] | None = None ,
322
331
** kwargs : NDArrayLike ,
323
332
) -> None :
324
333
"""Convenience function to save several NumPy arrays to the local file system, following a
@@ -334,22 +343,40 @@ async def save_group(
334
343
The zarr format to use when saving.
335
344
path : str or None, optional
336
345
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.
337
349
kwargs
338
350
NumPy arrays with data to save.
339
351
"""
340
352
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
+ )
342
357
or _default_zarr_version ()
343
358
)
344
359
345
360
if len (args ) == 0 and len (kwargs ) == 0 :
346
361
raise ValueError ("at least one array must be provided" )
347
362
aws = []
348
363
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
+ )
350
373
for k , arr in kwargs .items ():
351
374
_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
+ )
353
380
await asyncio .gather (* aws )
354
381
355
382
@@ -418,6 +445,7 @@ async def group(
418
445
zarr_format : ZarrFormat | None = None ,
419
446
meta_array : Any | None = None , # not used
420
447
attributes : dict [str , JSON ] | None = None ,
448
+ storage_options : dict [str , Any ] | None = None ,
421
449
) -> AsyncGroup :
422
450
"""Create a group.
423
451
@@ -444,6 +472,9 @@ async def group(
444
472
to users. Use `numpy.empty(())` by default.
445
473
zarr_format : {2, 3, None}, optional
446
474
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.
447
478
448
479
Returns
449
480
-------
@@ -453,7 +484,7 @@ async def group(
453
484
454
485
zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
455
486
456
- store_path = await make_store_path (store )
487
+ store_path = await make_store_path (store , storage_options = storage_options )
457
488
if path is not None :
458
489
store_path = store_path / path
459
490
@@ -472,7 +503,7 @@ async def group(
472
503
try :
473
504
return await AsyncGroup .open (store = store_path , zarr_format = zarr_format )
474
505
except (KeyError , FileNotFoundError ):
475
- return await AsyncGroup .create (
506
+ return await AsyncGroup .from_store (
476
507
store = store_path ,
477
508
zarr_format = zarr_format or _default_zarr_version (),
478
509
exists_ok = overwrite ,
@@ -481,14 +512,14 @@ async def group(
481
512
482
513
483
514
async def open_group (
484
- * , # Note: this is a change from v2
485
515
store : StoreLike | None = None ,
516
+ * , # Note: this is a change from v2
486
517
mode : AccessModeLiteral | None = None ,
487
518
cache_attrs : bool | None = None , # not used, default changed
488
519
synchronizer : Any = None , # not used
489
520
path : str | None = None ,
490
521
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 ,
492
523
zarr_version : ZarrFormat | None = None , # deprecated
493
524
zarr_format : ZarrFormat | None = None ,
494
525
meta_array : Any | None = None , # not used
@@ -548,10 +579,8 @@ async def open_group(
548
579
warnings .warn ("meta_array is not yet implemented" , RuntimeWarning , stacklevel = 2 )
549
580
if chunk_store is not None :
550
581
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 )
553
582
554
- store_path = await make_store_path (store , mode = mode )
583
+ store_path = await make_store_path (store , mode = mode , storage_options = storage_options )
555
584
if path is not None :
556
585
store_path = store_path / path
557
586
@@ -561,7 +590,7 @@ async def open_group(
561
590
try :
562
591
return await AsyncGroup .open (store_path , zarr_format = zarr_format )
563
592
except (KeyError , FileNotFoundError ):
564
- return await AsyncGroup .create (
593
+ return await AsyncGroup .from_store (
565
594
store_path ,
566
595
zarr_format = zarr_format or _default_zarr_version (),
567
596
exists_ok = True ,
@@ -575,7 +604,7 @@ async def create(
575
604
chunks : ChunkCoords | None = None , # TODO: v2 allowed chunks=True
576
605
dtype : npt .DTypeLike | None = None ,
577
606
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
579
608
order : MemoryOrder | None = None , # TODO: default change
580
609
store : str | StoreLike | None = None ,
581
610
synchronizer : Any | None = None ,
@@ -603,6 +632,7 @@ async def create(
603
632
) = None ,
604
633
codecs : Iterable [Codec | dict [str , JSON ]] | None = None ,
605
634
dimension_names : Iterable [str ] | None = None ,
635
+ storage_options : dict [str , Any ] | None = None ,
606
636
** kwargs : Any ,
607
637
) -> AsyncArray :
608
638
"""Create an array.
@@ -674,6 +704,9 @@ async def create(
674
704
to users. Use `numpy.empty(())` by default.
675
705
676
706
.. 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.
677
710
678
711
Returns
679
712
-------
@@ -725,7 +758,7 @@ async def create(
725
758
warnings .warn ("meta_array is not yet implemented" , RuntimeWarning , stacklevel = 2 )
726
759
727
760
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 )
729
762
if path is not None :
730
763
store_path = store_path / path
731
764
@@ -827,7 +860,7 @@ async def full_like(a: ArrayLike, **kwargs: Any) -> AsyncArray:
827
860
"""
828
861
like_kwargs = _like_args (a , kwargs )
829
862
if isinstance (a , AsyncArray ):
830
- kwargs .setdefault ("fill_value" , a .metadata .fill_value )
863
+ like_kwargs .setdefault ("fill_value" , a .metadata .fill_value )
831
864
return await full (** like_kwargs )
832
865
833
866
@@ -875,6 +908,7 @@ async def open_array(
875
908
zarr_version : ZarrFormat | None = None , # deprecated
876
909
zarr_format : ZarrFormat | None = None ,
877
910
path : PathLike | None = None ,
911
+ storage_options : dict [str , Any ] | None = None ,
878
912
** kwargs : Any , # TODO: type kwargs as valid args to save
879
913
) -> AsyncArray :
880
914
"""Open an array using file-mode-like semantics.
@@ -887,6 +921,9 @@ async def open_array(
887
921
The zarr format to use when saving.
888
922
path : string, optional
889
923
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.
890
927
**kwargs
891
928
Any keyword arguments to pass to the array constructor.
892
929
@@ -896,7 +933,7 @@ async def open_array(
896
933
The opened array.
897
934
"""
898
935
899
- store_path = await make_store_path (store )
936
+ store_path = await make_store_path (store , storage_options = storage_options )
900
937
if path is not None :
901
938
store_path = store_path / path
902
939
0 commit comments