88import numpy as np
99import numpy .typing as npt
1010
11- from zarr .abc .store import set_or_delete
11+ from zarr .abc .store import Store , set_or_delete
1212from zarr .codecs import BytesCodec
1313from zarr .codecs ._v2 import V2Compressor , V2Filters
1414from zarr .core .attributes import Attributes
1515from zarr .core .buffer import BufferPrototype , NDArrayLike , NDBuffer , default_buffer_prototype
16- from zarr .core .chunk_grids import RegularChunkGrid , _guess_chunks
16+ from zarr .core .chunk_grids import RegularChunkGrid , normalize_chunks
1717from zarr .core .chunk_key_encodings import (
1818 ChunkKeyEncoding ,
1919 DefaultChunkKeyEncoding ,
@@ -129,7 +129,7 @@ async def create(
129129 fill_value : Any | None = None ,
130130 attributes : dict [str , JSON ] | None = None ,
131131 # v3 only
132- chunk_shape : ChunkCoords | None = None ,
132+ chunk_shape : ChunkCoords | None = None , # TODO: handle bool and iterable of iterable types
133133 chunk_key_encoding : (
134134 ChunkKeyEncoding
135135 | tuple [Literal ["default" ], Literal ["." , "/" ]]
@@ -139,7 +139,7 @@ async def create(
139139 codecs : Iterable [Codec | dict [str , JSON ]] | None = None ,
140140 dimension_names : Iterable [str ] | None = None ,
141141 # v2 only
142- chunks : ShapeLike | None = None ,
142+ chunks : ShapeLike | None = None , # TODO: handle bool and iterable of iterable types
143143 dimension_separator : Literal ["." , "/" ] | None = None ,
144144 order : Literal ["C" , "F" ] | None = None ,
145145 filters : list [dict [str , JSON ]] | None = None ,
@@ -152,15 +152,14 @@ async def create(
152152
153153 shape = parse_shapelike (shape )
154154
155- if chunk_shape is None :
156- if chunks is None :
157- chunk_shape = chunks = _guess_chunks (shape = shape , typesize = np .dtype (dtype ).itemsize )
158- else :
159- chunks = parse_shapelike (chunks )
155+ if chunks is not None and chunk_shape is not None :
156+ raise ValueError ("Only one of chunk_shape or chunks can be provided." )
160157
161- chunk_shape = chunks
162- elif chunks is not None :
163- raise ValueError ("Only one of chunk_shape or chunks must be provided." )
158+ dtype = np .dtype (dtype )
159+ if chunks :
160+ _chunks = normalize_chunks (chunks , shape , dtype .itemsize )
161+ if chunk_shape :
162+ _chunks = normalize_chunks (chunk_shape , shape , dtype .itemsize )
164163
165164 if zarr_format == 3 :
166165 if dimension_separator is not None :
@@ -183,7 +182,7 @@ async def create(
183182 store_path ,
184183 shape = shape ,
185184 dtype = dtype ,
186- chunk_shape = chunk_shape ,
185+ chunk_shape = _chunks ,
187186 fill_value = fill_value ,
188187 chunk_key_encoding = chunk_key_encoding ,
189188 codecs = codecs ,
@@ -206,7 +205,7 @@ async def create(
206205 store_path ,
207206 shape = shape ,
208207 dtype = dtype ,
209- chunks = chunk_shape ,
208+ chunks = _chunks ,
210209 dimension_separator = dimension_separator ,
211210 fill_value = fill_value ,
212211 order = order ,
@@ -393,6 +392,10 @@ async def open(
393392 metadata = ArrayV3Metadata .from_dict (json .loads (zarr_json_bytes .to_bytes ())),
394393 )
395394
395+ @property
396+ def store (self ) -> Store :
397+ return self .store_path .store
398+
396399 @property
397400 def ndim (self ) -> int :
398401 return len (self .metadata .shape )
@@ -697,6 +700,10 @@ def open(
697700 async_array = sync (AsyncArray .open (store ))
698701 return cls (async_array )
699702
703+ @property
704+ def store (self ) -> Store :
705+ return self ._async_array .store
706+
700707 @property
701708 def ndim (self ) -> int :
702709 return self ._async_array .ndim
0 commit comments