@@ -332,6 +332,7 @@ async def save(
332332 * args : NDArrayLike ,
333333 zarr_version : ZarrFormat | None = None , # deprecated
334334 zarr_format : ZarrFormat | None = None ,
335+ mode : AccessModeLiteral | None = None ,
335336 path : str | None = None ,
336337 ** kwargs : Any , # TODO: type kwargs as valid args to save
337338) -> None :
@@ -345,19 +346,31 @@ async def save(
345346 NumPy arrays with data to save.
346347 zarr_format : {2, 3, None}, optional
347348 The zarr format to use when saving.
349+ mode: {'r', 'r+', 'a', 'w', 'w-'}, optional
350+ Persistence mode: 'r' means read only (must exist); 'r+' means
351+ read/write (must exist); 'a' means read/write (create if doesn't
352+ exist); 'w' means create (overwrite if exists); 'w-' means create
353+ (fail if exists).
348354 path : str or None, optional
349355 The path within the group where the arrays will be saved.
350356 **kwargs
351357 NumPy arrays with data to save.
352358 """
353359 zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
354360
361+ for arg in args :
362+ if not isinstance (arg , np .ndarray ):
363+ raise TypeError ("All arguments must be numpy arrays" )
364+ for k , v in kwargs .items ():
365+ if not isinstance (v , np .ndarray ):
366+ raise TypeError (f"Keyword argument '{ k } ' must be a numpy array" )
367+
355368 if len (args ) == 0 and len (kwargs ) == 0 :
356369 raise ValueError ("at least one array must be provided" )
357370 if len (args ) == 1 and len (kwargs ) == 0 :
358- await save_array (store , args [0 ], zarr_format = zarr_format , path = path )
371+ await save_array (store , args [0 ], zarr_format = zarr_format , mode = mode , path = path )
359372 else :
360- await save_group (store , * args , zarr_format = zarr_format , path = path , ** kwargs )
373+ await save_group (store , * args , zarr_format = zarr_format , mode = mode , path = path , ** kwargs )
361374
362375
363376async def save_array (
@@ -366,6 +379,7 @@ async def save_array(
366379 * ,
367380 zarr_version : ZarrFormat | None = None , # deprecated
368381 zarr_format : ZarrFormat | None = None ,
382+ mode : AccessModeLiteral | None = None ,
369383 path : str | None = None ,
370384 storage_options : dict [str , Any ] | None = None ,
371385 ** kwargs : Any , # TODO: type kwargs as valid args to create
@@ -381,6 +395,11 @@ async def save_array(
381395 NumPy array with data to save.
382396 zarr_format : {2, 3, None}, optional
383397 The zarr format to use when saving.
398+ mode: {'r', 'r+', 'a', 'w', 'w-'}, optional
399+ Persistence mode: 'r' means read only (must exist); 'r+' means
400+ read/write (must exist); 'a' means read/write (create if doesn't
401+ exist); 'w' means create (overwrite if exists); 'w-' means create
402+ (fail if exists).
384403 path : str or None, optional
385404 The path within the store where the array will be saved.
386405 storage_options : dict
@@ -394,7 +413,6 @@ async def save_array(
394413 or _default_zarr_version ()
395414 )
396415
397- mode = kwargs .pop ("mode" , None )
398416 store_path = await make_store_path (store , path = path , mode = mode , storage_options = storage_options )
399417 new = await AsyncArray .create (
400418 store_path ,
@@ -412,6 +430,7 @@ async def save_group(
412430 * args : NDArrayLike ,
413431 zarr_version : ZarrFormat | None = None , # deprecated
414432 zarr_format : ZarrFormat | None = None ,
433+ mode : AccessModeLiteral | None = None ,
415434 path : str | None = None ,
416435 storage_options : dict [str , Any ] | None = None ,
417436 ** kwargs : NDArrayLike ,
@@ -427,6 +446,11 @@ async def save_group(
427446 NumPy arrays with data to save.
428447 zarr_format : {2, 3, None}, optional
429448 The zarr format to use when saving.
449+ mode: {'r', 'r+', 'a', 'w', 'w-'}, optional
450+ Persistence mode: 'r' means read only (must exist); 'r+' means
451+ read/write (must exist); 'a' means read/write (create if doesn't
452+ exist); 'w' means create (overwrite if exists); 'w-' means create
453+ (fail if exists).
430454 path : str or None, optional
431455 Path within the store where the group will be saved.
432456 storage_options : dict
@@ -452,6 +476,7 @@ async def save_group(
452476 store ,
453477 arr ,
454478 zarr_format = zarr_format ,
479+ mode = mode ,
455480 path = f"{ path } /arr_{ i } " ,
456481 storage_options = storage_options ,
457482 )
@@ -460,7 +485,12 @@ async def save_group(
460485 _path = f"{ path } /{ k } " if path is not None else k
461486 aws .append (
462487 save_array (
463- store , arr , zarr_format = zarr_format , path = _path , storage_options = storage_options
488+ store ,
489+ arr ,
490+ zarr_format = zarr_format ,
491+ mode = mode ,
492+ path = _path ,
493+ storage_options = storage_options ,
464494 )
465495 )
466496 await asyncio .gather (* aws )
0 commit comments