66
77import zarr .codecs
88import zarr .storage
9- from zarr .core .array import init_array
9+ from zarr .core .array import AsyncArray , init_array
1010from zarr .storage import LocalStore , ZipStore
1111from zarr .storage ._common import StorePath
1212
4242 save_group ,
4343)
4444from 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+ )
4652from zarr .storage import MemoryStore
4753from zarr .storage ._utils import normalize_path
4854from zarr .testing .utils import gpu_test
@@ -70,11 +76,11 @@ def test_create(memory_store: Store) -> None:
7076
7177 # create array with float shape
7278 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]
7480
7581 # create array with float chunk shape
7682 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]
7884
7985
8086# TODO: parametrize over everything this function takes
@@ -185,10 +191,27 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
185191 assert z .read_only
186192
187193 # path not found
188- with pytest .raises (FileNotFoundError ):
194+ with pytest .raises (NodeNotFoundError ):
189195 zarr .api .synchronous .open (store = "doesnotexist" , mode = "r" , zarr_format = zarr_format )
190196
191197
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+
192215@pytest .mark .parametrize ("store" , ["memory" , "local" , "zip" ], indirect = True )
193216def test_v2_and_v3_exist_at_same_path (store : Store ) -> None :
194217 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
266289 assert isinstance (array , Array )
267290 assert_array_equal (array [:], data )
268291 else :
269- save (store , * args , path = path , ** kwargs ) # type: ignore [arg-type]
292+ save (store , * args , path = path , ** kwargs ) # type: ignore[arg-type]
270293 group = zarr .api .synchronous .open (store , path = path )
271294 assert isinstance (group , Group )
272295 for array in group .array_values ():
@@ -1208,13 +1231,13 @@ async def test_metadata_validation_error() -> None:
12081231 MetadataValidationError ,
12091232 match = "Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'." ,
12101233 ):
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]
12121235
12131236 with pytest .raises (
12141237 MetadataValidationError ,
12151238 match = "Invalid value for 'zarr_format'. Expected '2, 3, or None'. Got '3.0'." ,
12161239 ):
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]
12181241
12191242
12201243@pytest .mark .parametrize (
@@ -1224,7 +1247,7 @@ async def test_metadata_validation_error() -> None:
12241247)
12251248def test_open_array_with_mode_r_plus (store : Store , zarr_format : ZarrFormat ) -> None :
12261249 # 'r+' means read/write (must exist)
1227- with pytest .raises (FileNotFoundError ):
1250+ with pytest .raises (ArrayNotFoundError ):
12281251 zarr .open_array (store = store , mode = "r+" , zarr_format = zarr_format )
12291252 zarr .ones (store = store , shape = (3 , 3 ), zarr_format = zarr_format )
12301253 z2 = zarr .open_array (store = store , mode = "r+" )
0 commit comments