1- from codecs import Codec
21import pickle
3- from typing import Any , Literal
2+ from codecs import Codec
3+ from typing import TYPE_CHECKING , Any , Literal
44
55import numpy as np
66import numpy .typing as npt
1919)
2020from zarr .codecs .bytes import BytesCodec
2121from zarr .codecs .crc32c_ import Crc32cCodec
22- from zarr .codecs .sharding import ShardingJSON_V2 , ShardingJSON_V3
2322from zarr .core .buffer import NDArrayLike , default_buffer_prototype
2423from zarr .storage import StorePath
2524
2625from ..conftest import ArrayRequest
2726from .test_codecs import _AsyncArrayProxy , order_from_dim
2827
28+ if TYPE_CHECKING :
29+ from zarr .codecs .sharding import ShardingJSON_V2 , ShardingJSON_V3
30+
2931
3032@pytest .mark .parametrize ("index_location" , ["start" , "end" ])
3133@pytest .mark .parametrize ("chunk_shape" , [(32 , 32 ), (64 , 64 )])
32- @pytest .mark .parametrize ('codecs' , [(BytesCodec (),)])
33- @pytest .mark .parametrize ('index_codecs' , [(Crc32cCodec (),)])
34- def test_sharding_codec_to_json (index_location : Literal ["start" , "end" ], chunk_shape : tuple [int , ...], codecs : tuple [Codec , ...], index_codecs : tuple [Codec , ...]) -> None :
35- codec = ShardingCodec (chunk_shape = chunk_shape , codecs = codecs , index_location = index_location , index_codecs = index_codecs )
34+ @pytest .mark .parametrize ("codecs" , [(BytesCodec (),)])
35+ @pytest .mark .parametrize ("index_codecs" , [(Crc32cCodec (),)])
36+ def test_sharding_codec_to_json (
37+ index_location : Literal ["start" , "end" ],
38+ chunk_shape : tuple [int , ...],
39+ codecs : tuple [Codec , ...],
40+ index_codecs : tuple [Codec , ...],
41+ ) -> None :
42+ codec = ShardingCodec (
43+ chunk_shape = chunk_shape ,
44+ codecs = codecs ,
45+ index_location = index_location ,
46+ index_codecs = index_codecs ,
47+ )
3648 expected_v2 : ShardingJSON_V2 = {
3749 "id" : "sharding_indexed" ,
3850 "chunk_shape" : chunk_shape ,
@@ -43,10 +55,10 @@ def test_sharding_codec_to_json(index_location: Literal["start", "end"], chunk_s
4355 expected_v3 : ShardingJSON_V3 = {
4456 "name" : "sharding_indexed" ,
4557 "configuration" : {
46- "chunk_shape" : chunk_shape ,
47- "codecs" : tuple (c .to_json (zarr_format = 3 ) for c in codecs ),
48- "index_codecs" : tuple (c .to_json (zarr_format = 3 ) for c in index_codecs ),
49- "index_location" : index_location ,
58+ "chunk_shape" : chunk_shape ,
59+ "codecs" : tuple (c .to_json (zarr_format = 3 ) for c in codecs ),
60+ "index_codecs" : tuple (c .to_json (zarr_format = 3 ) for c in index_codecs ),
61+ "index_location" : index_location ,
5062 },
5163 }
5264 assert codec .to_json (zarr_format = 2 ) == expected_v2
0 commit comments