@@ -4197,7 +4197,7 @@ async def init_array(
41974197
41984198 from zarr .codecs .sharding import ShardingCodec , ShardingCodecIndexLocation
41994199
4200- dtype_wrapped = parse_data_type (dtype , zarr_format = zarr_format )
4200+ zdtype = parse_data_type (dtype , zarr_format = zarr_format )
42014201 shape_parsed = parse_shapelike (shape )
42024202 chunk_key_encoding_parsed = _parse_chunk_key_encoding (
42034203 chunk_key_encoding , zarr_format = zarr_format
@@ -4211,11 +4211,15 @@ async def init_array(
42114211 else :
42124212 await ensure_no_existing_node (store_path , zarr_format = zarr_format )
42134213
4214+ item_size = 1
4215+ if isinstance (zdtype , HasItemSize ):
4216+ item_size = zdtype .item_size
4217+
42144218 shard_shape_parsed , chunk_shape_parsed = _auto_partition (
42154219 array_shape = shape_parsed ,
42164220 shard_shape = shards ,
42174221 chunk_shape = chunks ,
4218- item_size = dtype_wrapped . to_dtype (). itemsize ,
4222+ item_size = item_size ,
42194223 )
42204224 chunks_out : tuple [int , ...]
42214225 meta : ArrayV2Metadata | ArrayV3Metadata
@@ -4231,7 +4235,7 @@ async def init_array(
42314235 raise ValueError ("Zarr format 2 arrays do not support `serializer`." )
42324236
42334237 filters_parsed , compressor_parsed = _parse_chunk_encoding_v2 (
4234- compressor = compressors , filters = filters , dtype = dtype_wrapped
4238+ compressor = compressors , filters = filters , dtype = zdtype
42354239 )
42364240 if dimension_names is not None :
42374241 raise ValueError ("Zarr format 2 arrays do not support dimension names." )
@@ -4242,7 +4246,7 @@ async def init_array(
42424246
42434247 meta = AsyncArray ._create_metadata_v2 (
42444248 shape = shape_parsed ,
4245- dtype = dtype_wrapped ,
4249+ dtype = zdtype ,
42464250 chunks = chunk_shape_parsed ,
42474251 dimension_separator = chunk_key_encoding_parsed .separator ,
42484252 fill_value = fill_value ,
@@ -4256,7 +4260,7 @@ async def init_array(
42564260 compressors = compressors ,
42574261 filters = filters ,
42584262 serializer = serializer ,
4259- dtype = dtype_wrapped ,
4263+ dtype = zdtype ,
42604264 )
42614265 sub_codecs = cast (tuple [Codec , ...], (* array_array , array_bytes , * bytes_bytes ))
42624266 codecs_out : tuple [Codec , ...]
@@ -4271,7 +4275,7 @@ async def init_array(
42714275 )
42724276 sharding_codec .validate (
42734277 shape = chunk_shape_parsed ,
4274- dtype = dtype_wrapped ,
4278+ dtype = zdtype ,
42754279 chunk_grid = RegularChunkGrid (chunk_shape = shard_shape_parsed ),
42764280 )
42774281 codecs_out = (sharding_codec ,)
@@ -4287,7 +4291,7 @@ async def init_array(
42874291
42884292 meta = AsyncArray ._create_metadata_v3 (
42894293 shape = shape_parsed ,
4290- dtype = dtype_wrapped ,
4294+ dtype = zdtype ,
42914295 fill_value = fill_value ,
42924296 chunk_shape = chunks_out ,
42934297 chunk_key_encoding = chunk_key_encoding_parsed ,
0 commit comments