@@ -645,6 +645,29 @@ def from_dict(
645
645
store_path : StorePath ,
646
646
data : dict [str , JSON ],
647
647
) -> AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ]:
648
+ """
649
+ Create a Zarr array from a dictionary, with support for both Zarr v2 and v3 metadata.
650
+
651
+ Parameters
652
+ ----------
653
+ store_path : StorePath
654
+ The path within the store where the array should be created.
655
+
656
+ data : dict
657
+ A dictionary representing the array data. This dictionary should include necessary metadata
658
+ for the array, such as shape, dtype, and other attributes. The format of the metadata
659
+ will determine whether a Zarr v2 or v3 array is created.
660
+
661
+ Returns
662
+ -------
663
+ AsyncArray[ArrayV3Metadata] or AsyncArray[ArrayV2Metadata]
664
+ The created Zarr array, either using v2 or v3 metadata based on the provided data.
665
+
666
+ Raises
667
+ ------
668
+ ValueError
669
+ If the dictionary data is invalid or incompatible with either Zarr v2 or v3 array creation.
670
+ """
648
671
metadata = parse_array_metadata (data )
649
672
return cls (metadata = metadata , store_path = store_path )
650
673
@@ -1040,6 +1063,9 @@ async def getitem(
1040
1063
return await self ._get_selection (indexer , prototype = prototype )
1041
1064
1042
1065
async def _save_metadata (self , metadata : ArrayMetadata , ensure_parents : bool = False ) -> None :
1066
+ """
1067
+ Asynchronously save the array metadata.
1068
+ """
1043
1069
to_save = metadata .to_buffer_dict (default_buffer_prototype ())
1044
1070
awaitables = [set_or_delete (self .store_path / key , value ) for key , value in to_save .items ()]
1045
1071
@@ -1118,6 +1144,39 @@ async def setitem(
1118
1144
value : npt .ArrayLike ,
1119
1145
prototype : BufferPrototype | None = None ,
1120
1146
) -> None :
1147
+ """
1148
+ Asynchronously set values in the array using basic indexing.
1149
+
1150
+ Parameters
1151
+ ----------
1152
+ selection : BasicSelection
1153
+ The selection defining the region of the array to set.
1154
+
1155
+ value : numpy.typing.ArrayLike
1156
+ The values to be written into the selected region of the array.
1157
+
1158
+ prototype : BufferPrototype or None, optional
1159
+ A prototype buffer that defines the structure and properties of the array chunks being modified.
1160
+ If None, the default buffer prototype is used. Default is None.
1161
+
1162
+ Returns
1163
+ -------
1164
+ None
1165
+ This method does not return any value.
1166
+
1167
+ Raises
1168
+ ------
1169
+ IndexError
1170
+ If the selection is out of bounds for the array.
1171
+
1172
+ ValueError
1173
+ If the values are not compatible with the array's dtype or shape.
1174
+
1175
+ Notes
1176
+ -----
1177
+ - This method is asynchronous and should be awaited.
1178
+ - Supports basic indexing, where the selection is contiguous and does not involve advanced indexing.
1179
+ """
1121
1180
if prototype is None :
1122
1181
prototype = default_buffer_prototype ()
1123
1182
indexer = BasicIndexer (
@@ -1128,6 +1187,32 @@ async def setitem(
1128
1187
return await self ._set_selection (indexer , value , prototype = prototype )
1129
1188
1130
1189
async def resize (self , new_shape : ShapeLike , delete_outside_chunks : bool = True ) -> None :
1190
+ """
1191
+ Asynchronously resize the array to a new shape.
1192
+
1193
+ Parameters
1194
+ ----------
1195
+ new_shape : ChunkCoords
1196
+ The desired new shape of the array.
1197
+
1198
+ delete_outside_chunks : bool, optional
1199
+ If True (default), chunks that fall outside the new shape will be deleted. If False,
1200
+ the data in those chunks will be preserved.
1201
+
1202
+ Returns
1203
+ -------
1204
+ AsyncArray
1205
+ The resized array.
1206
+
1207
+ Raises
1208
+ ------
1209
+ ValueError
1210
+ If the new shape is incompatible with the current array's chunking configuration.
1211
+
1212
+ Notes
1213
+ -----
1214
+ - This method is asynchronous and should be awaited.
1215
+ """
1131
1216
new_shape = parse_shapelike (new_shape )
1132
1217
assert len (new_shape ) == len (self .metadata .shape )
1133
1218
new_metadata = self .metadata .update_shape (new_shape )
@@ -1210,6 +1295,31 @@ async def append(self, data: npt.ArrayLike, axis: int = 0) -> ChunkCoords:
1210
1295
return new_shape
1211
1296
1212
1297
async def update_attributes (self , new_attributes : dict [str , JSON ]) -> Self :
1298
+ """
1299
+ Asynchronously update the array's attributes.
1300
+
1301
+ Parameters
1302
+ ----------
1303
+ new_attributes : dict of str to JSON
1304
+ A dictionary of new attributes to update or add to the array. The keys represent attribute
1305
+ names, and the values must be JSON-compatible.
1306
+
1307
+ Returns
1308
+ -------
1309
+ AsyncArray
1310
+ The array with the updated attributes.
1311
+
1312
+ Raises
1313
+ ------
1314
+ ValueError
1315
+ If the attributes are invalid or incompatible with the array's metadata.
1316
+
1317
+ Notes
1318
+ -----
1319
+ - This method is asynchronous and should be awaited.
1320
+ - The updated attributes will be merged with existing attributes, and any conflicts will be
1321
+ overwritten by the new values.
1322
+ """
1213
1323
# metadata.attributes is "frozen" so we simply clear and update the dict
1214
1324
self .metadata .attributes .clear ()
1215
1325
self .metadata .attributes .update (new_attributes )
@@ -1328,6 +1438,28 @@ def from_dict(
1328
1438
store_path : StorePath ,
1329
1439
data : dict [str , JSON ],
1330
1440
) -> Array :
1441
+ """
1442
+ Create a Zarr array from a dictionary.
1443
+
1444
+ Parameters
1445
+ ----------
1446
+ store_path : StorePath
1447
+ The path within the store where the array should be created.
1448
+
1449
+ data : dict
1450
+ A dictionary representing the array data. This dictionary should include necessary metadata
1451
+ for the array, such as shape, dtype, fill value, and attributes.
1452
+
1453
+ Returns
1454
+ -------
1455
+ Array
1456
+ The created Zarr array.
1457
+
1458
+ Raises
1459
+ ------
1460
+ ValueError
1461
+ If the dictionary data is invalid or missing required fields for array creation.
1462
+ """
1331
1463
async_array = AsyncArray .from_dict (store_path = store_path , data = data )
1332
1464
return cls (async_array )
1333
1465
@@ -2934,6 +3066,30 @@ def append(self, data: npt.ArrayLike, axis: int = 0) -> ChunkCoords:
2934
3066
return sync (self ._async_array .append (data , axis = axis ))
2935
3067
2936
3068
def update_attributes (self , new_attributes : dict [str , JSON ]) -> Array :
3069
+ """
3070
+ Update the array's attributes.
3071
+
3072
+ Parameters
3073
+ ----------
3074
+ new_attributes : dict
3075
+ A dictionary of new attributes to update or add to the array. The keys represent attribute
3076
+ names, and the values must be JSON-compatible.
3077
+
3078
+ Returns
3079
+ -------
3080
+ Array
3081
+ The array with the updated attributes.
3082
+
3083
+ Raises
3084
+ ------
3085
+ ValueError
3086
+ If the attributes are invalid or incompatible with the array's metadata.
3087
+
3088
+ Notes
3089
+ -----
3090
+ - The updated attributes will be merged with existing attributes, and any conflicts will be
3091
+ overwritten by the new values.
3092
+ """
2937
3093
# TODO: remove this cast when type inference improves
2938
3094
new_array = sync (self ._async_array .update_attributes (new_attributes ))
2939
3095
# TODO: remove this cast when type inference improves
0 commit comments