Skip to content

fix(codecs): reshape flattened numcodecs filter output on encode - #4560

Open
Yi-111-a wants to merge 2 commits into
zarr-developers:mainfrom
Yi-111-a:fix-numcodecs-encode-reshape
Open

Yi-111-a wants to merge 2 commits into
zarr-developers:mainfrom
Yi-111-a:fix-numcodecs-encode-reshape

Conversation

@Yi-111-a

Copy link
Copy Markdown

Closes #4553.

What and why

_NumcodecsArrayArrayCodec._encode_sync now reshapes a flattened numcodecs filter output back to the chunk shape before handing it to the next codec, mirroring what _decode_sync already does on the way out. Filters like Delta and FixedScaleOffset return a 1-D array, so downstream codecs (e.g. the imagecodecs JPEG-XR serializer from the issue, or a TransposeCodec right after the filter) previously received a 1 × N chunk instead of the 2-D chunk shape: writing failed outright (axes don't match array, JpegxrError) or data was silently corrupted. Filenames in the issue's 'patched' output show the exact failures this fixes.

Only flattened outputs whose element count equals the chunk size are reshaped; shape-changing ArrayArray codecs keep their output (e.g. PackBits, whose packed output is ceil(N/8) + 1 bytes — reshaping that would have been wrong).

Note: the issue's proposed patch reshaped unconditionally; this PR keeps that behavior only when the flattened output is exactly chunk-sized so PackBits (covered by existing tests) still works.

Testing

New test_generic_filter_flattened_output_reshaped (Delta → TransposeCodec) fails on main and passes with this change; new test_generic_filter_packedbits_output_not_reshaped guards the size-mismatch path. Full tests/test_codecs/test_numcodecs.py (94), test_transpose.py and test_fastpath_equivalence.py all pass; ruff check and ruff format --check clean.

@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Oct 26, 2026
@Yi-111-a
Yi-111-a force-pushed the fix-numcodecs-encode-reshape branch from 2be4fd7 to e3d6d20 Compare October 26, 2026 03:47
@github-actions github-actions Bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Oct 26, 2026
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.71%. Comparing base (957a5f6) to head (e3d6d20).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4560   +/-   ##
=======================================
  Coverage   94.71%   94.71%           
=======================================
  Files          94       94           
  Lines       13663    13665    +2     
=======================================
+ Hits        12941    12943    +2     
  Misses        722      722           
Files with missing lines Coverage Δ
src/zarr/codecs/numcodecs/_codecs.py 95.53% <100.00%> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_NumcodecsArrayArrayCodec._encode_sync does not reshape the data on encode

1 participant