Skip to content

Commit 3cf8ab1

Browse files
dcheriand-v-b
andauthored
Don't overwrite codec config values when set. (#700)
* Don't overwrite codec config values when set. A codec doesn't know where it is in the codec pipeline, so it cannot know whether `array_spec.dtype` should match `codec.dtype` or not. * little more * FIx test * fix test --------- Co-authored-by: Davis Bennett <[email protected]>
1 parent 8a0bd3b commit 3cf8ab1

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

numcodecs/tests/test_zarr3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_generic_compressor(
9191
(numcodecs.zarr3.Delta, {"dtype": "float32"}),
9292
(numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 25.5}),
9393
(numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 51, "astype": "uint16"}),
94-
(numcodecs.zarr3.AsType, {"encode_dtype": "float32", "decode_dtype": "float64"}),
94+
(numcodecs.zarr3.AsType, {"encode_dtype": "float32", "decode_dtype": "float32"}),
9595
],
9696
ids=[
9797
"delta",

numcodecs/zarr3.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def __init__(self, **codec_config: JSON) -> None:
271271
super().__init__(**codec_config)
272272

273273
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:
274-
if array_spec.dtype.itemsize != self.codec_config.get("elementsize"):
274+
if self.codec_config.get("elementsize", None) is None:
275275
return Shuffle(**{**self.codec_config, "elementsize": array_spec.dtype.itemsize})
276276
return self # pragma: no cover
277277

@@ -308,7 +308,7 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
308308
return chunk_spec
309309

310310
def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset:
311-
if str(array_spec.dtype) != self.codec_config.get("dtype"):
311+
if self.codec_config.get("dtype", None) is None:
312312
return FixedScaleOffset(**{**self.codec_config, "dtype": str(array_spec.dtype)})
313313
return self
314314

@@ -321,7 +321,7 @@ def __init__(self, **codec_config: JSON) -> None:
321321
super().__init__(**codec_config)
322322

323323
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Quantize:
324-
if str(array_spec.dtype) != self.codec_config.get("dtype"):
324+
if self.codec_config.get("dtype", None) is None:
325325
return Quantize(**{**self.codec_config, "dtype": str(array_spec.dtype)})
326326
return self
327327

@@ -356,8 +356,7 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
356356
return replace(chunk_spec, dtype=np.dtype(self.codec_config["encode_dtype"])) # type: ignore[arg-type]
357357

358358
def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType:
359-
decode_dtype = self.codec_config.get("decode_dtype")
360-
if str(array_spec.dtype) != decode_dtype:
359+
if self.codec_config.get("decode_dtype", None) is None:
361360
return AsType(**{**self.codec_config, "decode_dtype": str(array_spec.dtype)})
362361
return self
363362

0 commit comments

Comments
 (0)