diff --git a/changes/4558.bugfix.md b/changes/4558.bugfix.md new file mode 100644 index 0000000000..1aaea5f423 --- /dev/null +++ b/changes/4558.bugfix.md @@ -0,0 +1,3 @@ +Arrays that apply a Numcodecs `Delta` or `FixedScaleOffset` filter followed by a +`TransposeCodec` now read back the values that were written. The filter now +decodes the transposed chunk in logical (C) order rather than memory order. diff --git a/src/zarr/codecs/numcodecs/_codecs.py b/src/zarr/codecs/numcodecs/_codecs.py index 5cd1611447..5681c16c54 100644 --- a/src/zarr/codecs/numcodecs/_codecs.py +++ b/src/zarr/codecs/numcodecs/_codecs.py @@ -155,7 +155,7 @@ def __init__(self, **codec_config: JSON) -> None: super().__init__(**codec_config) def _decode_sync(self, chunk_data: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer: - chunk_ndarray = chunk_data.as_ndarray_like() + chunk_ndarray = np.ascontiguousarray(chunk_data.as_ndarray_like()) out = self._codec.decode(chunk_ndarray) return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape)) diff --git a/tests/test_codecs/test_numcodecs.py b/tests/test_codecs/test_numcodecs.py index 085af102e0..d41ba3073d 100644 --- a/tests/test_codecs/test_numcodecs.py +++ b/tests/test_codecs/test_numcodecs.py @@ -139,9 +139,11 @@ def test_generic_compressor(codec_class: type[_numcodecs._NumcodecsBytesBytesCod "astype", ], ) +@pytest.mark.parametrize("transpose", [False, True]) def test_generic_filter( codec_class: type[_numcodecs._NumcodecsArrayArrayCodec], codec_config: dict[str, JSON], + transpose: bool, ) -> None: data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16)) @@ -153,6 +155,7 @@ def test_generic_filter( fill_value=0, filters=[ codec_class(**codec_config), + *([TransposeCodec(order=(1, 0))] if transpose else []), ], )