2020from zarr .abc .store import Store , set_or_delete
2121from zarr .core ._info import GroupInfo
2222from zarr .core .array import (
23+ DEFAULT_FILL_VALUE ,
2324 Array ,
2425 AsyncArray ,
2526 CompressorLike ,
7172 from zarr .core .buffer import Buffer , BufferPrototype
7273 from zarr .core .chunk_key_encodings import ChunkKeyEncodingLike
7374 from zarr .core .common import MemoryOrder
75+ from zarr .core .dtype import ZDTypeLike
7476
7577logger = logging .getLogger ("zarr.group" )
7678
@@ -999,22 +1001,24 @@ async def create_array(
9991001 self ,
10001002 name : str ,
10011003 * ,
1002- shape : ShapeLike ,
1003- dtype : npt .DTypeLike ,
1004+ shape : ShapeLike | None = None ,
1005+ dtype : ZDTypeLike | None = None ,
1006+ data : np .ndarray [Any , np .dtype [Any ]] | None = None ,
10041007 chunks : ChunkCoords | Literal ["auto" ] = "auto" ,
10051008 shards : ShardsLike | None = None ,
10061009 filters : FiltersLike = "auto" ,
10071010 compressors : CompressorsLike = "auto" ,
10081011 compressor : CompressorLike = "auto" ,
10091012 serializer : SerializerLike = "auto" ,
1010- fill_value : Any | None = 0 ,
1013+ fill_value : Any | None = DEFAULT_FILL_VALUE ,
10111014 order : MemoryOrder | None = None ,
10121015 attributes : dict [str , JSON ] | None = None ,
10131016 chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
10141017 dimension_names : DimensionNames = None ,
10151018 storage_options : dict [str , Any ] | None = None ,
10161019 overwrite : bool = False ,
1017- config : ArrayConfig | ArrayConfigLike | None = None ,
1020+ config : ArrayConfigLike | None = None ,
1021+ write_data : bool = True ,
10181022 ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
10191023 """Create an array within this group.
10201024
@@ -1102,6 +1106,11 @@ async def create_array(
11021106 Whether to overwrite an array with the same name in the store, if one exists.
11031107 config : ArrayConfig or ArrayConfigLike, optional
11041108 Runtime configuration for the array.
1109+ write_data : bool
1110+ If a pre-existing array-like object was provided to this function via the ``data`` parameter
1111+ then ``write_data`` determines whether the values in that array-like object should be
1112+ written to the Zarr array created by this function. If ``write_data`` is ``False``, then the
1113+ array will be left empty.
11051114
11061115 Returns
11071116 -------
@@ -1116,6 +1125,7 @@ async def create_array(
11161125 name = name ,
11171126 shape = shape ,
11181127 dtype = dtype ,
1128+ data = data ,
11191129 chunks = chunks ,
11201130 shards = shards ,
11211131 filters = filters ,
@@ -1130,6 +1140,7 @@ async def create_array(
11301140 storage_options = storage_options ,
11311141 overwrite = overwrite ,
11321142 config = config ,
1143+ write_data = write_data ,
11331144 )
11341145
11351146 @deprecated ("Use AsyncGroup.create_array instead." )
@@ -2411,22 +2422,24 @@ def create_array(
24112422 self ,
24122423 name : str ,
24132424 * ,
2414- shape : ShapeLike ,
2415- dtype : npt .DTypeLike ,
2425+ shape : ShapeLike | None = None ,
2426+ dtype : ZDTypeLike | None = None ,
2427+ data : np .ndarray [Any , np .dtype [Any ]] | None = None ,
24162428 chunks : ChunkCoords | Literal ["auto" ] = "auto" ,
24172429 shards : ShardsLike | None = None ,
24182430 filters : FiltersLike = "auto" ,
24192431 compressors : CompressorsLike = "auto" ,
24202432 compressor : CompressorLike = "auto" ,
24212433 serializer : SerializerLike = "auto" ,
2422- fill_value : Any | None = 0 ,
2423- order : MemoryOrder | None = "C" ,
2434+ fill_value : Any | None = DEFAULT_FILL_VALUE ,
2435+ order : MemoryOrder | None = None ,
24242436 attributes : dict [str , JSON ] | None = None ,
24252437 chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
24262438 dimension_names : DimensionNames = None ,
24272439 storage_options : dict [str , Any ] | None = None ,
24282440 overwrite : bool = False ,
2429- config : ArrayConfig | ArrayConfigLike | None = None ,
2441+ config : ArrayConfigLike | None = None ,
2442+ write_data : bool = True ,
24302443 ) -> Array :
24312444 """Create an array within this group.
24322445
@@ -2437,10 +2450,13 @@ def create_array(
24372450 name : str
24382451 The name of the array relative to the group. If ``path`` is ``None``, the array will be located
24392452 at the root of the store.
2440- shape : ChunkCoords
2441- Shape of the array.
2442- dtype : npt.DTypeLike
2443- Data type of the array.
2453+ shape : ChunkCoords, optional
2454+ Shape of the array. Can be ``None`` if ``data`` is provided.
2455+ dtype : npt.DTypeLike | None
2456+ Data type of the array. Can be ``None`` if ``data`` is provided.
2457+ data : Array-like data to use for initializing the array. If this parameter is provided, the
2458+ ``shape`` and ``dtype`` parameters must be identical to ``data.shape`` and ``data.dtype``,
2459+ or ``None``.
24442460 chunks : ChunkCoords, optional
24452461 Chunk shape of the array.
24462462 If not specified, default are guessed based on the shape and dtype.
@@ -2514,6 +2530,11 @@ def create_array(
25142530 Whether to overwrite an array with the same name in the store, if one exists.
25152531 config : ArrayConfig or ArrayConfigLike, optional
25162532 Runtime configuration for the array.
2533+ write_data : bool
2534+ If a pre-existing array-like object was provided to this function via the ``data`` parameter
2535+ then ``write_data`` determines whether the values in that array-like object should be
2536+ written to the Zarr array created by this function. If ``write_data`` is ``False``, then the
2537+ array will be left empty.
25172538
25182539 Returns
25192540 -------
@@ -2528,6 +2549,7 @@ def create_array(
25282549 name = name ,
25292550 shape = shape ,
25302551 dtype = dtype ,
2552+ data = data ,
25312553 chunks = chunks ,
25322554 shards = shards ,
25332555 fill_value = fill_value ,
@@ -2541,6 +2563,7 @@ def create_array(
25412563 overwrite = overwrite ,
25422564 storage_options = storage_options ,
25432565 config = config ,
2566+ write_data = write_data ,
25442567 )
25452568 )
25462569 )
@@ -2813,7 +2836,7 @@ def array(
28132836 compressors : CompressorsLike = "auto" ,
28142837 compressor : CompressorLike = None ,
28152838 serializer : SerializerLike = "auto" ,
2816- fill_value : Any | None = 0 ,
2839+ fill_value : Any | None = DEFAULT_FILL_VALUE ,
28172840 order : MemoryOrder | None = "C" ,
28182841 attributes : dict [str , JSON ] | None = None ,
28192842 chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
0 commit comments