77import numpy as np
88import numpy .typing as npt
99
10+ from zarr .abc .store import Store
1011from zarr .core .array import Array , AsyncArray , get_array_metadata
1112from zarr .core .common import JSON , AccessModeLiteral , ChunkCoords , MemoryOrder , ZarrFormat
1213from zarr .core .config import config
1314from zarr .core .group import AsyncGroup
1415from zarr .core .metadata .v2 import ArrayV2Metadata
1516from zarr .core .metadata .v3 import ArrayV3Metadata
16- from zarr .store import (
17+ from zarr .storage import (
1718 StoreLike ,
19+ StorePath ,
1820 make_store_path ,
1921)
2022
@@ -225,6 +227,7 @@ async def open(
225227 Return type depends on what exists in the given store.
226228 """
227229 zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
230+
228231 store_path = await make_store_path (store , mode = mode , storage_options = storage_options )
229232
230233 if path is not None :
@@ -243,9 +246,9 @@ async def open(
243246 return await open_group (store = store_path , zarr_format = zarr_format , mode = mode , ** kwargs )
244247
245248 try :
246- return await open_array (store = store_path , zarr_format = zarr_format , mode = mode , ** kwargs )
249+ return await open_array (store = store_path , zarr_format = zarr_format , ** kwargs )
247250 except KeyError :
248- return await open_group (store = store_path , zarr_format = zarr_format , mode = mode , ** kwargs )
251+ return await open_group (store = store_path , zarr_format = zarr_format , ** kwargs )
249252
250253
251254async def open_consolidated (* args : Any , ** kwargs : Any ) -> AsyncGroup :
@@ -319,7 +322,8 @@ async def save_array(
319322 or _default_zarr_version ()
320323 )
321324
322- store_path = await make_store_path (store , mode = "w" , storage_options = storage_options )
325+ mode = kwargs .pop ("mode" , None )
326+ store_path = await make_store_path (store , mode = mode , storage_options = storage_options )
323327 if path is not None :
324328 store_path = store_path / path
325329 new = await AsyncArray .create (
@@ -496,7 +500,9 @@ async def group(
496500
497501 zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
498502
499- store_path = await make_store_path (store , storage_options = storage_options )
503+ mode = None if isinstance (store , Store ) else cast (AccessModeLiteral , "a" )
504+
505+ store_path = await make_store_path (store , mode = mode , storage_options = storage_options )
500506 if path is not None :
501507 store_path = store_path / path
502508
@@ -769,7 +775,11 @@ async def create(
769775 if meta_array is not None :
770776 warnings .warn ("meta_array is not yet implemented" , RuntimeWarning , stacklevel = 2 )
771777
772- mode = kwargs .pop ("mode" , cast (AccessModeLiteral , "r" if read_only else "w" ))
778+ mode = kwargs .pop ("mode" , None )
779+ if mode is None :
780+ if not isinstance (store , Store | StorePath ):
781+ mode = "a"
782+
773783 store_path = await make_store_path (store , mode = mode , storage_options = storage_options )
774784 if path is not None :
775785 store_path = store_path / path
@@ -945,7 +955,8 @@ async def open_array(
945955 The opened array.
946956 """
947957
948- store_path = await make_store_path (store , storage_options = storage_options )
958+ mode = kwargs .pop ("mode" , None )
959+ store_path = await make_store_path (store , mode = mode )
949960 if path is not None :
950961 store_path = store_path / path
951962
0 commit comments