diff --git a/numcodecs/tests/test_zarr3.py b/numcodecs/tests/test_zarr3.py index a40b658f..0d8ecc74 100644 --- a/numcodecs/tests/test_zarr3.py +++ b/numcodecs/tests/test_zarr3.py @@ -91,7 +91,7 @@ def test_generic_compressor( (numcodecs.zarr3.Delta, {"dtype": "float32"}), (numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 25.5}), (numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 51, "astype": "uint16"}), - (numcodecs.zarr3.AsType, {"encode_dtype": "float32", "decode_dtype": "float64"}), + (numcodecs.zarr3.AsType, {"encode_dtype": "float32", "decode_dtype": "float32"}), ], ids=[ "delta", diff --git a/numcodecs/zarr3.py b/numcodecs/zarr3.py index 78293514..f1743ffb 100644 --- a/numcodecs/zarr3.py +++ b/numcodecs/zarr3.py @@ -271,7 +271,7 @@ def __init__(self, **codec_config: JSON) -> None: super().__init__(**codec_config) def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle: - if array_spec.dtype.itemsize != self.codec_config.get("elementsize"): + if self.codec_config.get("elementsize", None) is None: return Shuffle(**{**self.codec_config, "elementsize": array_spec.dtype.itemsize}) return self # pragma: no cover @@ -308,7 +308,7 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec: return chunk_spec def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset: - if str(array_spec.dtype) != self.codec_config.get("dtype"): + if self.codec_config.get("dtype", None) is None: return FixedScaleOffset(**{**self.codec_config, "dtype": str(array_spec.dtype)}) return self @@ -321,7 +321,7 @@ def __init__(self, **codec_config: JSON) -> None: super().__init__(**codec_config) def evolve_from_array_spec(self, array_spec: ArraySpec) -> Quantize: - if str(array_spec.dtype) != self.codec_config.get("dtype"): + if self.codec_config.get("dtype", None) is None: return Quantize(**{**self.codec_config, "dtype": str(array_spec.dtype)}) return self @@ -356,8 +356,7 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec: return replace(chunk_spec, dtype=np.dtype(self.codec_config["encode_dtype"])) # type: ignore[arg-type] def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType: - decode_dtype = self.codec_config.get("decode_dtype") - if str(array_spec.dtype) != decode_dtype: + if self.codec_config.get("decode_dtype", None) is None: return AsType(**{**self.codec_config, "decode_dtype": str(array_spec.dtype)}) return self