Skip to content

fix(vlen): fill a non-contiguous out in decode - #917

Open
d-v-b wants to merge 1 commit into
zarr-developers:mainfrom
d-v-b:fix/vlen-non-contiguous-out
Open

d-v-b wants to merge 1 commit into
zarr-developers:mainfrom
d-v-b:fix/vlen-non-contiguous-out

Conversation

@d-v-b

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

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

The VLen codecs (VLenUTF8, VLenBytes and VLenArray) fill a non-contiguous out passed to decode. For layouts that numpy cannot flatten without a copy they decoded into that copy and returned out unchanged. If such an out is read-only they raise ValueError.

Relationship to #916

What was wrong, and the change
  • check_out_param flattens out with out.reshape(-1, order='A'). For an array such as base[::2] (every other row), numpy cannot do that as a view and returns a copy.
  • The decoders wrote the decoded items into that copy. Released versions (0.17.1) returned the filled copy; on main, since decode(buf, out=out) returns out itself, the caller gets back its own array, untouched, and no error.
  • decode now copies the items back into out when the flattened array does not share memory with it. An empty out is left alone, so an empty read-only out still works.
  • A read-only non-contiguous out raises ValueError ("assignment destination is read-only"): the items cannot be stored, and returning out unfilled would be wrong data.
Tests
  • tests/test_vlen_out.py, for all three codecs: five layouts that numpy cannot flatten as a view (the test asserts that), checking that out is returned, holds the decoded items in C order, and that the memory around it is untouched; the read-only refusal; and the empty read-only case.
  • Run locally by the agent: 18 of the 21 new tests fail against a build of main and all pass on this branch; the full suite passes on this branch (894 passed, without the optional zfpy and pcodec); ruff and mypy are clean.
  • Not verified: GitHub CI.

🤖 Generated with Claude Code

`check_out_param` flattens `out` with `reshape`, which returns a copy when
numpy cannot flatten the array as a view. The decoders then filled that copy
and returned the caller's `out` unchanged. They now copy the decoded items
back into `out` when it was flattened into a copy. A read-only `out` of such
a layout raises `ValueError`.

Assisted-by: ClaudeCode:claude-fable-5.2
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b5561d0) to head (72fef16).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #917   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         1196      1196           
=========================================
  Hits          1196      1196           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant