Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/4553.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve the declared chunk shape after Numcodecs filters and decode transposed chunks in logical C order.
3 changes: 2 additions & 1 deletion src/zarr/codecs/numcodecs/_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -164,6 +164,7 @@ def _encode_sync(self, chunk_data: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
# would be encoded in transposed element order (gh-3558)
chunk_ndarray = np.ascontiguousarray(chunk_data.as_ndarray_like())
out = self._codec.encode(chunk_ndarray)
out = out.reshape(self.resolve_metadata(chunk_spec).shape)
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out)

async def _encode_single(self, chunk_data: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_codecs/test_numcodecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from zarr import config, create_array, open_array
from zarr.abc.numcodec import _is_numcodec, _is_numcodec_cls
from zarr.codecs import TransposeCodec
from zarr.codecs import numcodecs as _numcodecs
from zarr.errors import UnknownCodecError
from zarr.registry import get_codec_class, get_numcodec
Expand Down Expand Up @@ -135,9 +136,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))

Expand All @@ -149,6 +152,7 @@ def test_generic_filter(
fill_value=0,
filters=[
codec_class(**codec_config),
*([TransposeCodec(order=(1, 0))] if transpose else []),
],
)

Expand Down
Loading