Skip to content

feat: narrow partial reads of uncompressed chunks within a single row - #1

Open
bendichter wants to merge 1 commit into
bytes-partial-decodefrom
partial-decode-leading-index
Open

bendichter wants to merge 1 commit into
bytes-partial-decodefrom
partial-decode-leading-index

Conversation

@bendichter

@bendichter bendichter commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Stacked on bytes-partial-decode (zarr-developers#4458). This PR is against that branch in the fork so the diff shows only the new change.

The parent PR reads the rows along the first axis that a selection touches. This extends it to the case where the selection touches a single row: the same row window is then applied along the next axis, and so on. For a (T, Y, X) chunk, arr[t, y0:y1, x0:x1] fetches rows y0 to y1 of frame t instead of the whole frame, and arr[t, y, x] fetches one item.

For example, say you have a stack of image frames through time (i.e. a video): (T, Y, X), and you wanted a region of a single frame.

  • Previously: The entire chunk is read, potentially reading many frames you don't need.
  • bytes-partial-decode: Only the desired row (frame) is read, but you must read the entire row (frame)
  • This PR: This will read a region of the desired frame, sub-selecting only the rows of interest (but only if a single frame is selected)

How it works:

  • _axis_window is the per-axis logic that _row_window had: the first and last index a selector touches, and the selector shifted to start at zero.
  • _block_window walks the axes from the first. It records each axis's window and continues to the next axis only while the window is a single index. It returns the block's offset in items, the block's shape, and the shifted selection.
  • The block keeps the narrowed axes with length 1, so it has the same number of axes as the chunk and the shifted selection applies to it unchanged.
  • A selection that touches more than one row is read exactly as before. Trimming the first and last row of a multi-row window would save less than one row and the fetched bytes would no longer be a rectangular block.

For reviewers

  • The exact-length handling of store responses from the parent PR is unchanged; it now works on the block's byte range.
  • test_block_window checks, for each case, that the shifted selection picks the same items from the block as the original selection does from the chunk.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/ (extends the parent PR's changes/4458.feature.md; needs its own file if opened upstream separately)
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

🤖 Generated with Claude Code

When a selection touches one index along the first axis, apply the same
row window along the next axis, and so on. arr[t, y0:y1, x0:x1] then
fetches rows y0 to y1 of frame t instead of the whole frame, and a
single item is fetched for a point.

The fetched block keeps the narrowed axes with length 1, so the shifted
selection applies to it unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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