6
6
7
7
import zarr .codecs
8
8
import zarr .storage
9
- from zarr .core .array import init_array
9
+ from zarr .core .array import AsyncArray , init_array
10
10
from zarr .storage import LocalStore , ZipStore
11
11
from zarr .storage ._common import StorePath
12
12
42
42
save_group ,
43
43
)
44
44
from zarr .core .buffer import NDArrayLike
45
- from zarr .errors import MetadataValidationError , ZarrDeprecationWarning , ZarrUserWarning
45
+ from zarr .errors import (
46
+ ArrayNotFoundError ,
47
+ MetadataValidationError ,
48
+ NodeNotFoundError ,
49
+ ZarrDeprecationWarning ,
50
+ ZarrUserWarning ,
51
+ )
46
52
from zarr .storage import MemoryStore
47
53
from zarr .storage ._utils import normalize_path
48
54
from zarr .testing .utils import gpu_test
@@ -70,11 +76,11 @@ def test_create(memory_store: Store) -> None:
70
76
71
77
# create array with float shape
72
78
with pytest .raises (TypeError ):
73
- z = create (shape = (400.5 , 100 ), store = store , overwrite = True ) # type: ignore [arg-type]
79
+ z = create (shape = (400.5 , 100 ), store = store , overwrite = True ) # type: ignore[arg-type]
74
80
75
81
# create array with float chunk shape
76
82
with pytest .raises (TypeError ):
77
- z = create (shape = (400 , 100 ), chunks = (16 , 16.5 ), store = store , overwrite = True ) # type: ignore [arg-type]
83
+ z = create (shape = (400 , 100 ), chunks = (16 , 16.5 ), store = store , overwrite = True ) # type: ignore[arg-type]
78
84
79
85
80
86
# TODO: parametrize over everything this function takes
@@ -185,10 +191,27 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
185
191
assert z .read_only
186
192
187
193
# path not found
188
- with pytest .raises (FileNotFoundError ):
194
+ with pytest .raises (NodeNotFoundError ):
189
195
zarr .api .synchronous .open (store = "doesnotexist" , mode = "r" , zarr_format = zarr_format )
190
196
191
197
198
+ @pytest .mark .asyncio
199
+ async def test_async_array_open_array_not_found () -> None :
200
+ """Test that AsyncArray.open raises ArrayNotFoundError when array doesn't exist"""
201
+ store = MemoryStore ()
202
+ # Try to open an array that does not exist
203
+ with pytest .raises (ArrayNotFoundError ):
204
+ await AsyncArray .open (store , zarr_format = 2 )
205
+
206
+
207
+ def test_array_open_array_not_found_sync () -> None :
208
+ """Test that Array.open raises ArrayNotFoundError when array doesn't exist"""
209
+ store = MemoryStore ()
210
+ # Try to open an array that does not exist
211
+ with pytest .raises (ArrayNotFoundError ):
212
+ Array .open (store )
213
+
214
+
192
215
@pytest .mark .parametrize ("store" , ["memory" , "local" , "zip" ], indirect = True )
193
216
def test_v2_and_v3_exist_at_same_path (store : Store ) -> None :
194
217
zarr .create_array (store , shape = (10 ,), dtype = "uint8" , zarr_format = 3 )
@@ -266,7 +289,7 @@ def test_save(store: Store, n_args: int, n_kwargs: int, path: None | str) -> Non
266
289
assert isinstance (array , Array )
267
290
assert_array_equal (array [:], data )
268
291
else :
269
- save (store , * args , path = path , ** kwargs ) # type: ignore [arg-type]
292
+ save (store , * args , path = path , ** kwargs ) # type: ignore[arg-type]
270
293
group = zarr .api .synchronous .open (store , path = path )
271
294
assert isinstance (group , Group )
272
295
for array in group .array_values ():
@@ -1208,13 +1231,13 @@ async def test_metadata_validation_error() -> None:
1208
1231
MetadataValidationError ,
1209
1232
match = "Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'." ,
1210
1233
):
1211
- await zarr .api .asynchronous .open_group (zarr_format = "3.0" ) # type: ignore [arg-type]
1234
+ await zarr .api .asynchronous .open_group (zarr_format = "3.0" ) # type: ignore[arg-type]
1212
1235
1213
1236
with pytest .raises (
1214
1237
MetadataValidationError ,
1215
1238
match = "Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'." ,
1216
1239
):
1217
- await zarr .api .asynchronous .open_array (shape = (1 ,), zarr_format = "3.0" ) # type: ignore [arg-type]
1240
+ await zarr .api .asynchronous .open_array (shape = (1 ,), zarr_format = "3.0" ) # type: ignore[arg-type]
1218
1241
1219
1242
1220
1243
@pytest .mark .parametrize (
@@ -1224,7 +1247,7 @@ async def test_metadata_validation_error() -> None:
1224
1247
)
1225
1248
def test_open_array_with_mode_r_plus (store : Store , zarr_format : ZarrFormat ) -> None :
1226
1249
# 'r+' means read/write (must exist)
1227
- with pytest .raises (FileNotFoundError ):
1250
+ with pytest .raises (ArrayNotFoundError ):
1228
1251
zarr .open_array (store = store , mode = "r+" , zarr_format = zarr_format )
1229
1252
zarr .ones (store = store , shape = (3 , 3 ), zarr_format = zarr_format )
1230
1253
z2 = zarr .open_array (store = store , mode = "r+" )
0 commit comments