Skip to content

test(codecs): run codecs from other packages with a prototype zarr.config does not name - #475

Draft
d-v-b wants to merge 6 commits into
claude/silly-wozniak-87525bfrom
claude/third-party-codec-prototype
Draft

d-v-b wants to merge 6 commits into
claude/silly-wozniak-87525bfrom
claude/third-party-codec-prototype

Conversation

@d-v-b

@d-v-b d-v-b commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Adds a test suite that runs codec packages from outside zarr (imagecodecs, numcodecs' pcodec and zfpy codecs, and the zarrs-python codec pipeline) through reads and writes whose BufferPrototype differs from the buffer kind zarr.config names. The packages stay out of the default test environments; a third-party-codecs hatch environment, just third-party-codecs, and a CI job install and run them.

Stack: this PR sits on #474 (claude/silly-wozniak-87525b, codecs use the prototype they are given), which must merge first; this one stays a draft until then. It has no changelog fragment: it changes tests and CI only.

What the suite runs

tests/test_codecs/test_third_party_codecs.py has two tests over the same cases:

  • test_third_party_codecs_use_the_given_prototype: a round trip (partial write into an absent chunk or shard, full write, partial write; full and partial read) in three directions: config names the fake device kind and the call asks for the CPU prototype; config names the CPU kind and the call asks for the device kind; both name the device kind. It checks the read result's array type, its values, and (for MemoryStore) the buffer type of every chunk value the store receives.
  • test_third_party_codecs_read_no_buffer_config: the same round trip and checks with zarr.config naming a buffer kind that cannot be built, with host and device prototypes. This catches zarr building a buffer from zarr.config and converting it afterwards, which the first test cannot see.

Cases that read device arrays directly (numcodecs codecs, including imagecodecs' numcodecs codecs on v2, and zarrs' Rust code) fail on CuPy whatever zarr does, and the fake device array, being host memory underneath, would let them pass. They run with a host prototype only, as #474's test_buffer_prototype.py does for numcodecs. imagecodecs' zarr 3 codecs copy to the host themselves (as_numpy_array()) and run in every direction.

Case Package entry point Layouts Pipelines
imagecodecs-filters-compressors imagecodecs.zarr Delta, Xor, Byteshuffle, Zstd, Lz4, Checksum v3, v3 sharded, nested sharded Batched, Fused
imagecodecs-numcodecs (host only) imagecodecs.numcodecs Delta + Zstd v2 Batched, Fused
imagecodecs-pcodec, -zfp (+Blosc2), -png imagecodecs.zarr serializers v3, sharded, nested sharded Batched, Fused
numcodecs-pcodec (host only) zarr.codecs.numcodecs.PCodec / numcodecs.PCodec (pcodec) v3, sharded, nested sharded, v2 Batched, Fused
numcodecs-zfpy (host only) zarr.codecs.numcodecs.ZFPY / numcodecs.ZFPY (zfpy, full precision) v3, sharded, nested sharded, v2 Batched, Fused
zarrs (host only) zarrs.ZarrsCodecPipeline (strict, LocalStore) with zarr's codecs v3, sharded, nested sharded, v2 zarrs

The fake device buffer kind, the directions (including the unusable-config ones), the recording store and the round trip moved from test_buffer_prototype.py to tests/test_codecs/buffer_kinds.py; test_buffer_prototype.py collects and passes the same 133 test IDs as on #474's branch (19c0986). round_trip now casts its values to the array's data type (identical for int32).

No package registers codecs through the zarr.codecs entry-point group. imagecodecs registers its zarr 3 codecs with imagecodecs.zarr.register_codecs() (zarr.registry.register_codec), and zarrs registers a zarr.codec_pipeline entry point.

Per-package verdicts (local run, macOS arm64, Python 3.13)

Versions: imagecodecs 2026.11.11, pcodec 1.1.0, zfpy 1.0.1, zarrs 0.2.3, numcodecs 0.17.1, numpy 2.5.5. On #474's branch (19c0986), all 164 cases pass. On main (d06ed58) with the same test files, 96 fail.

  • imagecodecs: passes with the change; fails on main (72 of 124) in sharded and nested-sharded cases where the two kinds differ, nested-sharded when both name the device kind, v2, and the no-config test. Unsharded v3 passes on main: its codecs already build from chunk_spec.prototype.
  • numcodecs + pcodec: passes with the change; fails on main (12 of 16): sharded, nested-sharded and v2 with the host prototype under a device config, and the no-config test.
  • numcodecs + zfpy: passes with the change; fails on main (12 of 16), same pattern.
  • zarrs: passes on main and with the change (8 of 8). zarrs ignores the prototype; it fills out.as_ndarray_like() from Rust.
  • kvikio: not covered. Its zarr 3 integration is kvikio.zarr.GDSStore, a store, not a codec. kvikio-cu12 does not build on macOS arm64, and no environment here installs it.

No case fails only with the change.

Main's 96 failures, by error:

  • 46 RuntimeError: a buffer / an array buffer was built from zarr.config (no-config test)
  • 24 ValueError: Non-default buffer prototypes are not supported within shards. (FusedCodecPipeline, src/zarr/codecs/sharding.py)
  • 12 assertion failures on the result's array type or the store's buffer type
  • 8 TypeError: concatenate mixes host and device arrays (BatchedCodecPipeline shard assembly joining host index bytes to device chunk bytes)
  • 6 TypeError: a host buffer was given device memory (V2Codec / scatter_chunk)
Installability and the CI job
  • macOS arm64 (local), Python 3.13: imagecodecs, pcodec, zfpy, zarrs install from wheels; kvikio-cu12 fails to build.
  • Linux x86_64 (uv pip compile --only-binary :all:): Python 3.12 and 3.13 resolve all four; on 3.14 zarrs has no wheels, so the env pins Python 3.13.
  • zfpy 1.0.1.post0, the newest wheel on both platforms, breaks import numcodecs (its version parse fails on post0); Fix NumCodecs import with zfpy post-releases zarr-developers/numcodecs#893 fixes it. The env excludes that version.
  • The CI job (test.yml, third-party-codecs) first imports every package named by a case and asserts zarr comes from the checkout's src/ (zarrs requires zarr>=3.1, so a failed version lookup could install zarr from PyPI), then runs the suite. It is not in the test-complete gate: the packages float, so a third-party release could turn unrelated PRs red. Adding it to the gate, with pinned versions, is the maintainer's call.
  • In the default env the module skips: 164 skipped cases, with no new dependencies.
Limits
  • The fake device array is an np.ndarray subclass in host memory. NumPy calls refuse to mix it with host arrays, but C or Rust code that reads its buffer takes it as host memory. That is why numcodecs and zarrs cases run host-only; for imagecodecs' zarr 3 codecs the device directions show that zarr hands them the right kinds, not that they work on a GPU. A real-CuPy direction in the GPU job would close that.
  • Mutation checks (reviewer, round 1): no mutation is caught only by this suite; test_buffer_prototype.py covers zarr's own paths more tightly. This suite's value is that it runs the packages' real codecs and pipeline API, so a zarr change those packages feel shows up here.
Upstream issues found on the way
  • imagecodecs' numcodecs filters encode to bytes; a second filter with shape/dtype set refuses them (buf.shape=() does not match), and Xor without them calls .tobytes() on bytes. Without shape, Delta.decode on a 2-D chunk's flat buffer returns wrong values ([0,1,2,3] → [0,1,3,4]). All reproduce without zarr. The v2 case uses one filter with dtype and shape.
  • zfpy 1.0.1.post0 / numcodecs: see above (numcodecs#893).
Adversarial review

Round 1 (two fresh reviewers, one on detection power with mutation tests, one on env/CI/layout); nothing serious.

  • Missing no-config round trip: four zarr mutations (V2Codec decode/encode, shard index spec, empty shard reader) slipped past. Fixed in 648002e; confirmed by re-running the V2Codec mutation (12 failures, all in the new test).
  • Fake device kind is host memory to C/Rust code: documented in the module docstring and here (648002e, narrowed in e6755b1).
  • kvikio case ran nowhere and used the fake kind: removed (648002e).
  • CI import list duplicated the cases and could drift: now derived from CASES (648002e).
  • CI could test PyPI zarr if version lookup failed: now asserts zarr is under src/ (648002e).
  • Not in test-complete: left out, trade-off noted above.
  • Skip noise in default runs (164 skips): kept; each skip line names the missing package.
  • zarrs adds little prototype coverage: docstring says it checks CodecPipeline compatibility.

Round 2 (fresh reviewer, fix diff only); nothing serious.

  • Prefix string check could match .../zarr-python-other; assertion ran after importing the tests: fixed in e6755b1 (resolved-path is_relative_to, assertion first).
  • Docstring overstated which packages fail on CuPy: narrowed in e6755b1.
  • New test has no pipeline-class assertion: kept; the first test asserts it for the same cases.

Two consecutive rounds without a serious finding, so the review stopped there.

Round 3 (fresh reviewer, after the rebase onto #474: the host-only change and the move of #474's helpers); nothing serious.

  • The moved test_buffer_prototype.py runs the same test IDs with the same outcomes as fix(codecs): build buffers from the given prototype instead of zarr.config #474's; the moved code is byte-identical apart from renames.
  • The host-only rule matches the code: numcodecs wrappers, V2Codec and zarrs hand raw arrays to host-only code; every imagecodecs zarr 3 codec used goes through as_numpy_array(). Host-only cases still catch a numcodecs wrapper building from zarr.config (6 failures).
  • Two unused helpers left by the refactor: removed in 6bb96d5.
  • The host-only filter is written in both modules' _cases: kept; a shared Direction.on_host would tie the two, and can follow if the rule grows.

Rebase onto 19c0986 (#474's final review fixes): mechanical, so no new review round. The moved fake device kind was diffed against #474's (identical after the as_array_like() warning checks, 5066305); the moved test_buffer_prototype.py collects the same 133 test IDs as #474's and all pass; main's verdicts are unchanged.

🤖 Generated with Claude Code

d-v-b and others added 6 commits November 30, 2026 13:27
…nfig does not name

Add tests/test_codecs/test_third_party_codecs.py, which runs imagecodecs'
zarr 3 and numcodecs codecs, numcodecs' pcodec and zfpy codecs, and the
zarrs codec pipeline through reads and writes whose prototype differs from
the buffer kind zarr.config names, over v3, sharded, nested-sharded and v2
layouts. kvikio's GDSStore gets a case that runs only where kvikio installs.

Move the fake device buffer kind, the prototype/config directions, the
recording store and the round trip into tests/test_codecs/buffer_kinds.py
so both suites share them; test_buffer_prototype.py checks what it did.

The packages stay out of the default test environments: a
`third-party-codecs` hatch environment, `just third-party-codecs`, and a
CI job install and run them.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a round trip under a zarr.config buffer kind that cannot be built, which
catches zarr building a buffer from zarr.config and converting it afterwards
(V2Codec, the shard index, an empty shard reader). Document that the fake
device array is host memory to C and Rust code, so the device directions do
not show a package works on a GPU.

Drop the kvikio case: no environment installs kvikio, and its zarr 3
integration is a store run with the fake kind, not CUDA.

In CI, derive the import check from the cases, and fail if zarr does not
come from the checkout (zarrs requires zarr, so a broken version lookup
would install zarr from PyPI).

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check zarr comes from the checkout's src/ by resolved path rather than by
string prefix, and before importing the tests. Narrow the suite's note on
which packages read device arrays directly.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e only

numcodecs codecs and zarrs read device arrays directly, which fails on CuPy
whatever zarr does, and the fake device array would let them pass. Run
those cases, and imagecodecs' numcodecs codecs, with a host prototype only,
as test_buffer_prototype.py now does for numcodecs. Share the unusable-config
directions through buffer_kinds.py, and check the array and store buffer
kinds in the no-config test too.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…474 now does

DeviceBuffer.from_buffer and combine check the source array, not the
buffer class, matching test_buffer_prototype.py on #474.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-v-b
d-v-b force-pushed the claude/third-party-codec-prototype branch from 593dfe8 to 5066305 Compare November 30, 2026 12:29

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant