feat: Bytes partial decode - #4458
Open
bendichter wants to merge 6 commits into
Open
bendichter wants to merge 6 commits into
bendichter wants to merge 6 commits into
Conversation
BytesCodec now implements partial decoding. An uncompressed chunk is stored in C order, so each row along its first axis is a contiguous run of bytes; for a selection that does not touch every row, the rows from the first to the last one it touches are fetched with a single range request and the selection is applied to them. The pipeline already uses partial decoding when the array-to-bytes codec supports it and there are no array-to-array or bytes-to-bytes codecs, so this applies to uncompressed arrays only. Reading 100 rows of a single-chunk 20 MB array now fetches the bytes of those rows instead of the whole chunk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reads A boolean mask on the first axis, as from arr.oindex[mask], was trimmed to start at the first selected row but not to end at the last, so its length no longer matched the rows fetched and numpy raised an IndexError. The row window and the shifted selection are now computed together in _row_window, which trims the mask at both ends. This also gives mypy the narrowing it needs. FsspecStore over HTTP returns the whole object when a server ignores the Range header. The partial read then failed to reshape a chunk that the full read would have decoded, so a read that worked before this branch raised an error. A response longer than the requested range is now sliced to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zarr-python into bytes-partial-decode
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4458 +/- ##
==========================================
- Coverage 94.47% 94.46% -0.02%
==========================================
Files 93 93
Lines 13241 13284 +43
==========================================
+ Hits 12510 12549 +39
- Misses 731 735 +4
🚀 New features to boost your workflow:
|
d-v-b
reviewed
Oct 1, 2026
Comment on lines
+174
to
+177
| if len(chunk_bytes) > (stop - first) * row_bytes: | ||
| # The store sent the whole chunk, as an HTTP server that ignores | ||
| # the Range header does. | ||
| chunk_bytes = chunk_bytes[first * row_bytes : stop * row_bytes] |
Contributor
There was a problem hiding this comment.
this needs a test. if the store honored the byte range start but not the stop, then re-indexing from the start again will generate an invalid result.
because byte range handling is so important, we should probably set up stores in our test fixtures that span the range of byte range handling behavior, to ensure that branches like this get tested thoroughly
Contributor
|
thank you for this! would you mind implementing the same behavior for a synchronous method ( |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I am working with an application where data is stored uncompressed, with BytesCodec as the only codec, and I want to read small subregions of large chunks. Currently, zarr-python reads the entire chunk for every selection. That is necessary when a chunk is compressed, but not when BytesCodec is the only codec. This PR makes BytesCodec implement partial decoding, so it fetches only the range that corresponds to the rows of interest. Selections that touch every row, and chunks with any other codec, are read whole as before.
This helps any uncompressed array with large chunks, and especially virtual datasets, where the chunk layout comes from existing files. A contiguous HDF5 dataset, for example, becomes a single chunk that can be many GB. In an example I am working on, reading 100 samples from a 20 MB single-chunk array fetched 20 MB before this change and 2 KB after.
Author attestation
TODO
docs/user-guide/*.mdchanges/