38
38
GroupMetadata ,
39
39
create_hierarchy ,
40
40
)
41
- from zarr .core .metadata import ArrayMetadataDict , ArrayV2Metadata , ArrayV3Metadata
41
+ from zarr .core .metadata import ArrayMetadataDict , ArrayV2Metadata
42
42
from zarr .errors import GroupNotFoundError , NodeTypeValidationError
43
43
from zarr .storage import StorePath
44
44
from zarr .storage ._common import make_store_path
52
52
from zarr .core .buffer import NDArrayLikeOrScalar
53
53
from zarr .core .chunk_key_encodings import ChunkKeyEncoding
54
54
from zarr .storage import StoreLike
55
- from zarr .types import AnyArray
55
+ from zarr .types import AnyArray , AnyAsyncArray
56
56
57
57
# TODO: this type could use some more thought
58
- ArrayLike : TypeAlias = (
59
- AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ] | AnyArray | npt .NDArray [Any ]
60
- )
58
+ ArrayLike : TypeAlias = AnyAsyncArray | AnyArray | npt .NDArray [Any ]
61
59
PathLike = str
62
60
63
61
__all__ = [
@@ -309,7 +307,7 @@ async def open(
309
307
path : str | None = None ,
310
308
storage_options : dict [str , Any ] | None = None ,
311
309
** kwargs : Any , # TODO: type kwargs as valid args to open_array
312
- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] | AsyncGroup :
310
+ ) -> AnyAsyncArray | AsyncGroup :
313
311
"""Convenience function to open a group or array using file-mode-like semantics.
314
312
315
313
Parameters
@@ -564,9 +562,7 @@ async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None =
564
562
return await grp .tree (expand = expand , level = level )
565
563
566
564
567
- async def array (
568
- data : npt .ArrayLike | AnyArray , ** kwargs : Any
569
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
565
+ async def array (data : npt .ArrayLike | AnyArray , ** kwargs : Any ) -> AnyAsyncArray :
570
566
"""Create an array filled with `data`.
571
567
572
568
Parameters
@@ -898,7 +894,7 @@ async def create(
898
894
storage_options : dict [str , Any ] | None = None ,
899
895
config : ArrayConfigLike | None = None ,
900
896
** kwargs : Any ,
901
- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] :
897
+ ) -> AnyAsyncArray :
902
898
"""Create an array.
903
899
904
900
Parameters
@@ -1070,9 +1066,7 @@ async def create(
1070
1066
)
1071
1067
1072
1068
1073
- async def empty (
1074
- shape : ChunkCoords , ** kwargs : Any
1075
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1069
+ async def empty (shape : ChunkCoords , ** kwargs : Any ) -> AnyAsyncArray :
1076
1070
"""Create an empty array with the specified shape. The contents will be filled with the
1077
1071
array's fill value or zeros if no fill value is provided.
1078
1072
@@ -1093,9 +1087,7 @@ async def empty(
1093
1087
return await create (shape = shape , fill_value = None , ** kwargs )
1094
1088
1095
1089
1096
- async def empty_like (
1097
- a : ArrayLike , ** kwargs : Any
1098
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1090
+ async def empty_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
1099
1091
"""Create an empty array like `a`. The contents will be filled with the
1100
1092
array's fill value or zeros if no fill value is provided.
1101
1093
@@ -1122,9 +1114,7 @@ async def empty_like(
1122
1114
1123
1115
1124
1116
# TODO: add type annotations for fill_value and kwargs
1125
- async def full (
1126
- shape : ChunkCoords , fill_value : Any , ** kwargs : Any
1127
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1117
+ async def full (shape : ChunkCoords , fill_value : Any , ** kwargs : Any ) -> AnyAsyncArray :
1128
1118
"""Create an array, with `fill_value` being used as the default value for
1129
1119
uninitialized portions of the array.
1130
1120
@@ -1146,9 +1136,7 @@ async def full(
1146
1136
1147
1137
1148
1138
# TODO: add type annotations for kwargs
1149
- async def full_like (
1150
- a : ArrayLike , ** kwargs : Any
1151
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1139
+ async def full_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
1152
1140
"""Create a filled array like `a`.
1153
1141
1154
1142
Parameters
@@ -1169,9 +1157,7 @@ async def full_like(
1169
1157
return await full (** like_kwargs )
1170
1158
1171
1159
1172
- async def ones (
1173
- shape : ChunkCoords , ** kwargs : Any
1174
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1160
+ async def ones (shape : ChunkCoords , ** kwargs : Any ) -> AnyAsyncArray :
1175
1161
"""Create an array, with one being used as the default value for
1176
1162
uninitialized portions of the array.
1177
1163
@@ -1190,9 +1176,7 @@ async def ones(
1190
1176
return await create (shape = shape , fill_value = 1 , ** kwargs )
1191
1177
1192
1178
1193
- async def ones_like (
1194
- a : ArrayLike , ** kwargs : Any
1195
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1179
+ async def ones_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
1196
1180
"""Create an array of ones like `a`.
1197
1181
1198
1182
Parameters
@@ -1219,7 +1203,7 @@ async def open_array(
1219
1203
path : PathLike = "" ,
1220
1204
storage_options : dict [str , Any ] | None = None ,
1221
1205
** kwargs : Any , # TODO: type kwargs as valid args to save
1222
- ) -> AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] :
1206
+ ) -> AnyAsyncArray :
1223
1207
"""Open an array using file-mode-like semantics.
1224
1208
1225
1209
Parameters
@@ -1267,9 +1251,7 @@ async def open_array(
1267
1251
raise
1268
1252
1269
1253
1270
- async def open_like (
1271
- a : ArrayLike , path : str , ** kwargs : Any
1272
- ) -> AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ]:
1254
+ async def open_like (a : ArrayLike , path : str , ** kwargs : Any ) -> AnyAsyncArray :
1273
1255
"""Open a persistent array like `a`.
1274
1256
1275
1257
Parameters
@@ -1292,9 +1274,7 @@ async def open_like(
1292
1274
return await open_array (path = path , ** like_kwargs )
1293
1275
1294
1276
1295
- async def zeros (
1296
- shape : ChunkCoords , ** kwargs : Any
1297
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1277
+ async def zeros (shape : ChunkCoords , ** kwargs : Any ) -> AnyAsyncArray :
1298
1278
"""Create an array, with zero being used as the default value for
1299
1279
uninitialized portions of the array.
1300
1280
@@ -1313,9 +1293,7 @@ async def zeros(
1313
1293
return await create (shape = shape , fill_value = 0 , ** kwargs )
1314
1294
1315
1295
1316
- async def zeros_like (
1317
- a : ArrayLike , ** kwargs : Any
1318
- ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
1296
+ async def zeros_like (a : ArrayLike , ** kwargs : Any ) -> AnyAsyncArray :
1319
1297
"""Create an array of zeros like `a`.
1320
1298
1321
1299
Parameters
0 commit comments