@@ -573,3 +573,28 @@ async def test_use_consolidated_false(
573573 assert len ([x async for x in good .members ()]) == 2
574574 assert good .metadata .consolidated_metadata
575575 assert sorted (good .metadata .consolidated_metadata .metadata ) == ["a" , "b" ]
576+
577+
578+ @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
579+ @pytest .mark .parametrize ("fill_value" , [np .nan , np .inf , - np .inf ])
580+ async def test_consolidated_metadata_encodes_special_chars (
581+ memory_store : Store , zarr_format : ZarrFormat , fill_value : float
582+ ):
583+ root = await group (store = memory_store , zarr_format = zarr_format )
584+ _time = await root .create_array ("time" , shape = (12 ,), dtype = np .float64 , fill_value = fill_value )
585+ await zarr .api .asynchronous .consolidate_metadata (memory_store )
586+
587+ root = await group (store = memory_store , zarr_format = zarr_format )
588+ root_buffer = root .metadata .to_buffer_dict (default_buffer_prototype ())
589+
590+ if zarr_format == 2 :
591+ root_metadata = root_buffer [".zmetadata" ].to_bytes ().decode ("utf-8" )
592+ elif zarr_format == 3 :
593+ root_metadata = root_buffer ["zarr.json" ].to_bytes ().decode ("utf-8" )
594+
595+ if np .isnan (fill_value ):
596+ assert '"NaN"' in root_metadata
597+ elif np .isneginf (fill_value ):
598+ assert '"-Infinity"' in root_metadata
599+ elif np .isinf (fill_value ):
600+ assert '"Infinity"' in root_metadata
0 commit comments