12
12
from zarr .abc .numcodec import Numcodec , _is_numcodec_cls
13
13
from zarr .codecs import numcodecs as _numcodecs
14
14
from zarr .codecs ._v2 import codec_json_v2_to_v3
15
- from zarr .core .common import CodecJSON_V2 , ZarrFormat
16
15
from zarr .errors import ZarrUserWarning
17
16
from zarr .registry import get_numcodec
18
17
19
18
if TYPE_CHECKING :
20
19
from collections .abc import Iterator
21
20
21
+ from zarr .core .common import CodecJSON_V2 , ZarrFormat
22
+
22
23
CODECS_WITH_SPECS : Final = ("zstd" , "gzip" , "blosc" )
23
24
24
25
@@ -57,7 +58,7 @@ def codec_conf() -> Iterator[Any]:
57
58
58
59
59
60
def test_get_numcodec () -> None :
60
- assert get_numcodec ({"id" : "gzip" , "level" : 2 }) == GZip (level = 2 ) # type: ignore[typeddict-unknown-key]
61
+ assert get_numcodec ({"id" : "gzip" , "level" : 2 }) == GZip (level = 2 )
61
62
62
63
63
64
def test_is_numcodec () -> None :
@@ -227,7 +228,7 @@ def test_generic_filter_packbits() -> None:
227
228
b = open_array (a .store , mode = "r" )
228
229
np .testing .assert_array_equal (data , b [:, :])
229
230
230
- with pytest .raises (ValueError , match = ".*requires bool dtype.*" ):
231
+ with pytest .raises (ValueError , match = r ".*requires bool dtype.*" ):
231
232
create_array (
232
233
{},
233
234
shape = data .shape ,
@@ -456,7 +457,7 @@ def test_bytes_to_bytes_codec_json_v2_v3(
456
457
"""Test JSON serialization for bytes-to-bytes codecs in both V2 and V3 formats."""
457
458
codec = codec_class (** codec_config )
458
459
459
- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
460
+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
460
461
# Test V2 serialization
461
462
v2_json = codec .to_json (zarr_format = 2 )
462
463
assert v2_json == expected_v2
@@ -553,7 +554,7 @@ def test_array_to_array_codec_json_v2_v3(
553
554
codec = codec_class (** codec_config )
554
555
555
556
# Many codecs emit warnings about unstable specifications
556
- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
557
+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
557
558
# Test V2 serialization
558
559
v2_json = codec .to_json (zarr_format = 2 )
559
560
assert v2_json == expected_v2
@@ -655,10 +656,10 @@ def test_checksum_codec_json_v2_v3(
655
656
codec = codec_class (** codec_config )
656
657
657
658
# Helper function to compare dictionaries with potential numpy arrays
658
- def compare_json_dicts (actual , expected ) :
659
+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
659
660
if set (actual .keys ()) != set (expected .keys ()):
660
661
return False
661
- for key in actual . keys () :
662
+ for key in actual :
662
663
actual_val = actual [key ]
663
664
expected_val = expected [key ]
664
665
if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
@@ -675,7 +676,7 @@ def compare_json_dicts(actual, expected):
675
676
return True
676
677
677
678
# Many codecs emit warnings about unstable specifications
678
- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
679
+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
679
680
# Test V2 serialization
680
681
v2_json = codec .to_json (zarr_format = 2 )
681
682
assert compare_json_dicts (v2_json , expected_v2 ), (
@@ -812,18 +813,18 @@ def test_array_to_bytes_codec_json_v2_v3(
812
813
"""Test JSON serialization for array-to-bytes codecs in both V2 and V3 formats."""
813
814
try :
814
815
codec = codec_class (** codec_config )
815
- codec ._codec # Try to access the underlying codec to check if it's available
816
+ _ = codec ._codec # Try to access the underlying codec to check if it's available
816
817
except (ValueError , ImportError ) as e :
817
818
if "codec not available" in str (e ) or "not available" in str (e ):
818
819
pytest .skip (f"{ codec_class .codec_name } is not available: { e } " )
819
820
else :
820
821
raise
821
822
822
823
# Helper function to compare dictionaries with potential numpy arrays
823
- def compare_json_dicts (actual , expected ) :
824
+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
824
825
if set (actual .keys ()) != set (expected .keys ()):
825
826
return False
826
- for key in actual . keys () :
827
+ for key in actual :
827
828
actual_val = actual [key ]
828
829
expected_val = expected [key ]
829
830
if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
@@ -840,7 +841,7 @@ def compare_json_dicts(actual, expected):
840
841
return True
841
842
842
843
# Many codecs emit warnings about unstable specifications
843
- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
844
+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
844
845
# Test V2 serialization
845
846
v2_json = codec .to_json (zarr_format = 2 )
846
847
assert compare_json_dicts (v2_json , expected_v2 ), (
@@ -872,9 +873,6 @@ def compare_json_dicts(actual, expected):
872
873
873
874
def test_json_v3_string_format () -> None :
874
875
"""Test that V3 codecs can be serialized and deserialized from string format."""
875
- # Test with a simple codec
876
- codec = _numcodecs .LZ4 ()
877
-
878
876
# Test string-only V3 format (codec name without configuration)
879
877
v3_string = "lz4"
880
878
codec_from_string = _numcodecs .LZ4 .from_json (v3_string )
@@ -895,7 +893,7 @@ def test_json_mixed_format_compatibility() -> None:
895
893
original_codec = _numcodecs .Zlib (level = 9 )
896
894
897
895
# Create both formats
898
- with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ):
896
+ with pytest .warns (ZarrUserWarning , match = EXPECTED_WARNING_STR ): # noqa: PT031
899
897
v2_json = original_codec .to_json (zarr_format = 2 )
900
898
v3_json = original_codec .to_json (zarr_format = 3 )
901
899
@@ -917,14 +915,14 @@ def test_json_error_handling() -> None:
917
915
"""Test error handling for invalid JSON inputs."""
918
916
# Test None input
919
917
with pytest .raises (AttributeError ):
920
- _numcodecs .LZ4 .from_json (None ) # type: ignore[arg-type]
918
+ _numcodecs .LZ4 .from_json (None )
921
919
922
920
# Test list input (doesn't have get method)
923
921
with pytest .raises (AttributeError ):
924
- _numcodecs .LZ4 .from_json ([]) # type: ignore[arg-type]
922
+ _numcodecs .LZ4 .from_json ([])
925
923
926
924
927
- @pytest .mark .filterwarnings ("ignore" , category = ZarrUserWarning )
925
+ @pytest .mark .filterwarnings ("ignore::zarr.errors. ZarrUserWarning" )
928
926
@pytest .mark .parametrize (
929
927
("codec" , "expected" ),
930
928
[
@@ -1070,10 +1068,11 @@ def test_json_roundtrip_default_config(
1070
1068
)
1071
1069
1072
1070
1073
- def compare_json_dicts (actual , expected ):
1071
+ def compare_json_dicts (actual : Any , expected : Any ) -> bool :
1072
+ """Compare two dictionaries that may contain numpy arrays."""
1074
1073
if set (actual .keys ()) != set (expected .keys ()):
1075
1074
return False
1076
- for key in actual . keys () :
1075
+ for key in actual :
1077
1076
actual_val = actual [key ]
1078
1077
expected_val = expected [key ]
1079
1078
if isinstance (actual_val , np .ndarray ) and isinstance (expected_val , np .ndarray ):
0 commit comments