1717 open ,
1818 open_consolidated ,
1919)
20+ from zarr .api .synchronous import Group
2021from zarr .core .buffer import cpu , default_buffer_prototype
2122from zarr .core .group import ConsolidatedMetadata , GroupMetadata
2223from zarr .core .metadata import ArrayV3Metadata
2526
2627if TYPE_CHECKING :
2728 from zarr .abc .store import Store
28- from zarr .core .common import ZarrFormat
29+ from zarr .core .common import JSON , ZarrFormat
2930
3031
3132@pytest .fixture
32- async def memory_store_with_hierarchy (memory_store : Store ) -> None :
33+ async def memory_store_with_hierarchy (memory_store : Store ) -> Store :
3334 g = await group (store = memory_store , attributes = {"foo" : "bar" })
3435 dtype = "uint8"
3536 await g .create_array (name = "air" , shape = (1 , 2 , 3 ), dtype = dtype )
@@ -49,15 +50,15 @@ async def memory_store_with_hierarchy(memory_store: Store) -> None:
4950
5051
5152class TestConsolidated :
52- async def test_open_consolidated_false_raises (self ):
53+ async def test_open_consolidated_false_raises (self ) -> None :
5354 store = zarr .storage .MemoryStore ()
5455 with pytest .raises (TypeError , match = "use_consolidated" ):
55- await zarr .api .asynchronous .open_consolidated (store , use_consolidated = False )
56+ await zarr .api .asynchronous .open_consolidated (store , use_consolidated = False ) # type: ignore[arg-type]
5657
57- def test_open_consolidated_false_raises_sync (self ):
58+ def test_open_consolidated_false_raises_sync (self ) -> None :
5859 store = zarr .storage .MemoryStore ()
5960 with pytest .raises (TypeError , match = "use_consolidated" ):
60- zarr .open_consolidated (store , use_consolidated = False )
61+ zarr .open_consolidated (store , use_consolidated = False ) # type: ignore[arg-type]
6162
6263 async def test_consolidated (self , memory_store_with_hierarchy : Store ) -> None :
6364 # TODO: Figure out desired keys in
@@ -69,7 +70,7 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
6970 await consolidate_metadata (memory_store_with_hierarchy )
7071 group2 = await AsyncGroup .open (memory_store_with_hierarchy )
7172
72- array_metadata = {
73+ array_metadata : dict [ str , JSON ] = {
7374 "attributes" : {},
7475 "chunk_key_encoding" : {
7576 "configuration" : {"separator" : "/" },
@@ -186,13 +187,11 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
186187 group4 = await open_consolidated (store = memory_store_with_hierarchy )
187188 assert group4 .metadata == expected
188189
189- result_raw = json .loads (
190- (
191- await memory_store_with_hierarchy .get (
192- "zarr.json" , prototype = default_buffer_prototype ()
193- )
194- ).to_bytes ()
195- )["consolidated_metadata" ]
190+ val = await memory_store_with_hierarchy .get (
191+ "zarr.json" , prototype = default_buffer_prototype ()
192+ )
193+ assert val is not None
194+ result_raw = json .loads ((val ).to_bytes ())["consolidated_metadata" ]
196195 assert result_raw ["kind" ] == "inline"
197196 assert sorted (result_raw ["metadata" ]) == [
198197 "air" ,
@@ -206,7 +205,7 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None:
206205 "time" ,
207206 ]
208207
209- def test_consolidated_sync (self , memory_store ) :
208+ def test_consolidated_sync (self , memory_store : zarr . storage . MemoryStore ) -> None :
210209 g = zarr .api .synchronous .group (store = memory_store , attributes = {"foo" : "bar" })
211210 dtype = "uint8"
212211 g .create_array (name = "air" , shape = (1 , 2 , 3 ), dtype = dtype )
@@ -215,9 +214,9 @@ def test_consolidated_sync(self, memory_store):
215214 g .create_array (name = "time" , shape = (3 ,), dtype = dtype )
216215
217216 zarr .api .synchronous .consolidate_metadata (memory_store )
218- group2 = zarr . api . synchronous . Group .open (memory_store )
217+ group2 = Group .open (memory_store )
219218
220- array_metadata = {
219+ array_metadata : dict [ str , JSON ] = {
221220 "attributes" : {},
222221 "chunk_key_encoding" : {
223222 "configuration" : {"separator" : "/" },
@@ -306,8 +305,8 @@ async def test_non_root_node(self, memory_store_with_hierarchy: Store) -> None:
306305 assert "air" not in child .metadata .consolidated_metadata .metadata
307306 assert "grandchild" in child .metadata .consolidated_metadata .metadata
308307
309- def test_consolidated_metadata_from_dict (self ):
310- data = {"must_understand" : False }
308+ def test_consolidated_metadata_from_dict (self ) -> None :
309+ data : dict [ str , JSON ] = {"must_understand" : False }
311310
312311 # missing kind
313312 with pytest .raises (ValueError , match = "kind='None'" ):
@@ -329,16 +328,16 @@ def test_consolidated_metadata_from_dict(self):
329328 data ["metadata" ] = {}
330329 ConsolidatedMetadata .from_dict (data )
331330
332- def test_flatten (self ):
333- array_metadata = {
331+ def test_flatten (self ) -> None :
332+ array_metadata : dict [ str , JSON ] = {
334333 "attributes" : {},
335334 "chunk_key_encoding" : {
336335 "configuration" : {"separator" : "/" },
337336 "name" : "default" ,
338337 },
339338 "codecs" : ({"configuration" : {"endian" : "little" }, "name" : "bytes" },),
340339 "data_type" : "float64" ,
341- "fill_value" : np . float64 ( 0.0 ) ,
340+ "fill_value" : 0 ,
342341 "node_type" : "array" ,
343342 # "shape": (1, 2, 3),
344343 "zarr_format" : 3 ,
@@ -407,6 +406,17 @@ def test_flatten(self):
407406 },
408407 )
409408 result = metadata .flattened_metadata
409+ assert isinstance (metadata .metadata ["child" ], GroupMetadata )
410+ assert isinstance (metadata .metadata ["child" ].consolidated_metadata , ConsolidatedMetadata )
411+ assert isinstance (
412+ metadata .metadata ["child" ].consolidated_metadata .metadata ["grandchild" ], GroupMetadata
413+ )
414+ assert isinstance (
415+ metadata .metadata ["child" ]
416+ .consolidated_metadata .metadata ["grandchild" ]
417+ .consolidated_metadata ,
418+ ConsolidatedMetadata ,
419+ )
410420 expected = {
411421 "air" : metadata .metadata ["air" ],
412422 "lat" : metadata .metadata ["lat" ],
@@ -426,7 +436,7 @@ def test_flatten(self):
426436 }
427437 assert result == expected
428438
429- def test_invalid_metadata_raises (self ):
439+ def test_invalid_metadata_raises (self ) -> None :
430440 payload = {
431441 "kind" : "inline" ,
432442 "must_understand" : False ,
@@ -436,9 +446,9 @@ def test_invalid_metadata_raises(self):
436446 }
437447
438448 with pytest .raises (TypeError , match = "key='foo', type='list'" ):
439- ConsolidatedMetadata .from_dict (payload )
449+ ConsolidatedMetadata .from_dict (payload ) # type: ignore[arg-type]
440450
441- def test_to_dict_empty (self ):
451+ def test_to_dict_empty (self ) -> None :
442452 meta = ConsolidatedMetadata (
443453 metadata = {
444454 "empty" : GroupMetadata (
@@ -467,7 +477,7 @@ def test_to_dict_empty(self):
467477 assert result == expected
468478
469479 @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
470- async def test_open_consolidated_raises_async (self , zarr_format : ZarrFormat ):
480+ async def test_open_consolidated_raises_async (self , zarr_format : ZarrFormat ) -> None :
471481 store = zarr .storage .MemoryStore ()
472482 await AsyncGroup .from_store (store , zarr_format = zarr_format )
473483 with pytest .raises (ValueError ):
@@ -485,12 +495,15 @@ async def v2_consolidated_metadata_empty_dataset(
485495 b'{"metadata":{".zgroup":{"zarr_format":2}},"zarr_consolidated_format":1}'
486496 )
487497 return AsyncGroup ._from_bytes_v2 (
488- None , zgroup_bytes , zattrs_bytes = None , consolidated_metadata_bytes = zmetadata_bytes
498+ None , # type: ignore[arg-type]
499+ zgroup_bytes ,
500+ zattrs_bytes = None ,
501+ consolidated_metadata_bytes = zmetadata_bytes ,
489502 )
490503
491504 async def test_consolidated_metadata_backwards_compatibility (
492- self , v2_consolidated_metadata_empty_dataset
493- ):
505+ self , v2_consolidated_metadata_empty_dataset : AsyncGroup
506+ ) -> None :
494507 """
495508 Test that consolidated metadata handles a missing .zattrs key. This is necessary for backwards compatibility with zarr-python 2.x. See https://github.com/zarr-developers/zarr-python/issues/2694
496509 """
@@ -500,7 +513,7 @@ async def test_consolidated_metadata_backwards_compatibility(
500513 result = await zarr .api .asynchronous .open_consolidated (store , zarr_format = 2 )
501514 assert result .metadata == v2_consolidated_metadata_empty_dataset .metadata
502515
503- async def test_consolidated_metadata_v2 (self ):
516+ async def test_consolidated_metadata_v2 (self ) -> None :
504517 store = zarr .storage .MemoryStore ()
505518 g = await AsyncGroup .from_store (store , attributes = {"key" : "root" }, zarr_format = 2 )
506519 dtype = "uint8"
@@ -622,7 +635,7 @@ async def test_use_consolidated_for_children_members(
622635@pytest .mark .parametrize ("fill_value" , [np .nan , np .inf , - np .inf ])
623636async def test_consolidated_metadata_encodes_special_chars (
624637 memory_store : Store , zarr_format : ZarrFormat , fill_value : float
625- ):
638+ ) -> None :
626639 root = await group (store = memory_store , zarr_format = zarr_format )
627640 _child = await root .create_group ("child" , attributes = {"test" : fill_value })
628641 _time = await root .create_array ("time" , shape = (12 ,), dtype = np .float64 , fill_value = fill_value )
0 commit comments