20
20
from zarr .abc .store import Store , set_or_delete
21
21
from zarr .core ._info import GroupInfo
22
22
from zarr .core .array import (
23
+ DEFAULT_FILL_VALUE ,
23
24
Array ,
24
25
AsyncArray ,
25
26
CompressorLike ,
71
72
from zarr .core .buffer import Buffer , BufferPrototype
72
73
from zarr .core .chunk_key_encodings import ChunkKeyEncodingLike
73
74
from zarr .core .common import MemoryOrder
75
+ from zarr .core .dtype import ZDTypeLike
74
76
75
77
logger = logging .getLogger ("zarr.group" )
76
78
@@ -999,22 +1001,24 @@ async def create_array(
999
1001
self ,
1000
1002
name : str ,
1001
1003
* ,
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 ,
1004
1007
chunks : ChunkCoords | Literal ["auto" ] = "auto" ,
1005
1008
shards : ShardsLike | None = None ,
1006
1009
filters : FiltersLike = "auto" ,
1007
1010
compressors : CompressorsLike = "auto" ,
1008
1011
compressor : CompressorLike = "auto" ,
1009
1012
serializer : SerializerLike = "auto" ,
1010
- fill_value : Any | None = 0 ,
1013
+ fill_value : Any | None = DEFAULT_FILL_VALUE ,
1011
1014
order : MemoryOrder | None = None ,
1012
1015
attributes : dict [str , JSON ] | None = None ,
1013
1016
chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
1014
1017
dimension_names : DimensionNames = None ,
1015
1018
storage_options : dict [str , Any ] | None = None ,
1016
1019
overwrite : bool = False ,
1017
- config : ArrayConfig | ArrayConfigLike | None = None ,
1020
+ config : ArrayConfigLike | None = None ,
1021
+ write_data : bool = True ,
1018
1022
) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1019
1023
"""Create an array within this group.
1020
1024
@@ -1102,6 +1106,11 @@ async def create_array(
1102
1106
Whether to overwrite an array with the same name in the store, if one exists.
1103
1107
config : ArrayConfig or ArrayConfigLike, optional
1104
1108
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.
1105
1114
1106
1115
Returns
1107
1116
-------
@@ -1116,6 +1125,7 @@ async def create_array(
1116
1125
name = name ,
1117
1126
shape = shape ,
1118
1127
dtype = dtype ,
1128
+ data = data ,
1119
1129
chunks = chunks ,
1120
1130
shards = shards ,
1121
1131
filters = filters ,
@@ -1130,6 +1140,7 @@ async def create_array(
1130
1140
storage_options = storage_options ,
1131
1141
overwrite = overwrite ,
1132
1142
config = config ,
1143
+ write_data = write_data ,
1133
1144
)
1134
1145
1135
1146
@deprecated ("Use AsyncGroup.create_array instead." )
@@ -2411,22 +2422,24 @@ def create_array(
2411
2422
self ,
2412
2423
name : str ,
2413
2424
* ,
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 ,
2416
2428
chunks : ChunkCoords | Literal ["auto" ] = "auto" ,
2417
2429
shards : ShardsLike | None = None ,
2418
2430
filters : FiltersLike = "auto" ,
2419
2431
compressors : CompressorsLike = "auto" ,
2420
2432
compressor : CompressorLike = "auto" ,
2421
2433
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 ,
2424
2436
attributes : dict [str , JSON ] | None = None ,
2425
2437
chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
2426
2438
dimension_names : DimensionNames = None ,
2427
2439
storage_options : dict [str , Any ] | None = None ,
2428
2440
overwrite : bool = False ,
2429
- config : ArrayConfig | ArrayConfigLike | None = None ,
2441
+ config : ArrayConfigLike | None = None ,
2442
+ write_data : bool = True ,
2430
2443
) -> Array :
2431
2444
"""Create an array within this group.
2432
2445
@@ -2437,10 +2450,13 @@ def create_array(
2437
2450
name : str
2438
2451
The name of the array relative to the group. If ``path`` is ``None``, the array will be located
2439
2452
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``.
2444
2460
chunks : ChunkCoords, optional
2445
2461
Chunk shape of the array.
2446
2462
If not specified, default are guessed based on the shape and dtype.
@@ -2514,6 +2530,11 @@ def create_array(
2514
2530
Whether to overwrite an array with the same name in the store, if one exists.
2515
2531
config : ArrayConfig or ArrayConfigLike, optional
2516
2532
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.
2517
2538
2518
2539
Returns
2519
2540
-------
@@ -2528,6 +2549,7 @@ def create_array(
2528
2549
name = name ,
2529
2550
shape = shape ,
2530
2551
dtype = dtype ,
2552
+ data = data ,
2531
2553
chunks = chunks ,
2532
2554
shards = shards ,
2533
2555
fill_value = fill_value ,
@@ -2541,6 +2563,7 @@ def create_array(
2541
2563
overwrite = overwrite ,
2542
2564
storage_options = storage_options ,
2543
2565
config = config ,
2566
+ write_data = write_data ,
2544
2567
)
2545
2568
)
2546
2569
)
@@ -2813,7 +2836,7 @@ def array(
2813
2836
compressors : CompressorsLike = "auto" ,
2814
2837
compressor : CompressorLike = None ,
2815
2838
serializer : SerializerLike = "auto" ,
2816
- fill_value : Any | None = 0 ,
2839
+ fill_value : Any | None = DEFAULT_FILL_VALUE ,
2817
2840
order : MemoryOrder | None = "C" ,
2818
2841
attributes : dict [str , JSON ] | None = None ,
2819
2842
chunk_key_encoding : ChunkKeyEncodingLike | None = None ,
0 commit comments