7171
7272
7373def _infer_exists_ok (mode : AccessModeLiteral ) -> bool :
74+ """
75+ Check that an ``AccessModeLiteral`` is compatible with overwriting an existing Zarr node.
76+ """
7477 return mode in _OVERWRITE_MODES
7578
7679
@@ -410,13 +413,14 @@ async def save_array(
410413 arr = np .array (arr )
411414 shape = arr .shape
412415 chunks = getattr (arr , "chunks" , None ) # for array-likes with chunks attribute
416+ exists_ok = kwargs .pop ("exists_ok" , None ) or _infer_exists_ok (mode )
413417 new = await AsyncArray .create (
414418 store_path ,
415419 zarr_format = zarr_format ,
416420 shape = shape ,
417421 dtype = arr .dtype ,
418422 chunks = chunks ,
419- exists_ok = kwargs . pop ( " exists_ok" , None ) or _infer_exists_ok ( mode ) ,
423+ exists_ok = exists_ok ,
420424 ** kwargs ,
421425 )
422426 await new .setitem (slice (None ), arr )
@@ -617,9 +621,10 @@ async def group(
617621 try :
618622 return await AsyncGroup .open (store = store_path , zarr_format = zarr_format )
619623 except (KeyError , FileNotFoundError ):
624+ _zarr_format = zarr_format or _default_zarr_version ()
620625 return await AsyncGroup .from_store (
621626 store = store_path ,
622- zarr_format = zarr_format or _default_zarr_version () ,
627+ zarr_format = _zarr_format ,
623628 exists_ok = overwrite ,
624629 attributes = attributes ,
625630 )
@@ -726,10 +731,12 @@ async def open_group(
726731 except (KeyError , FileNotFoundError ):
727732 pass
728733 if mode in _CREATE_MODES :
734+ exists_ok = _infer_exists_ok (mode )
735+ _zarr_format = zarr_format or _default_zarr_version ()
729736 return await AsyncGroup .from_store (
730737 store_path ,
731- zarr_format = zarr_format or _default_zarr_version () ,
732- exists_ok = _infer_exists_ok ( mode ) ,
738+ zarr_format = _zarr_format ,
739+ exists_ok = exists_ok ,
733740 attributes = attributes ,
734741 )
735742 raise FileNotFoundError (f"Unable to find group: { store_path } " )
@@ -904,7 +911,7 @@ async def create(
904911 dtype = dtype ,
905912 compressor = compressor ,
906913 fill_value = fill_value ,
907- exists_ok = overwrite , # TODO: name change
914+ exists_ok = overwrite ,
908915 filters = filters ,
909916 dimension_separator = dimension_separator ,
910917 zarr_format = zarr_format ,
@@ -1074,7 +1081,7 @@ async def open_array(
10741081 If using an fsspec URL to create the store, these will be passed to
10751082 the backend implementation. Ignored otherwise.
10761083 **kwargs
1077- Any keyword arguments to pass to the ``create``.
1084+ Any keyword arguments to pass to ``create``.
10781085
10791086 Returns
10801087 -------
@@ -1091,10 +1098,12 @@ async def open_array(
10911098 return await AsyncArray .open (store_path , zarr_format = zarr_format )
10921099 except FileNotFoundError :
10931100 if not store_path .read_only :
1101+ exists_ok = _infer_exists_ok (mode )
1102+ _zarr_format = zarr_format or _default_zarr_version ()
10941103 return await create (
10951104 store = store_path ,
1096- zarr_format = zarr_format or _default_zarr_version () ,
1097- overwrite = _infer_exists_ok ( mode ) ,
1105+ zarr_format = _zarr_format ,
1106+ overwrite = exists_ok ,
10981107 ** kwargs ,
10991108 )
11001109 raise
0 commit comments