Repository navigation
feat: Bytes partial decode - #4458
bendichter wants to merge 10 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4458 +/- ##
==========================================
+ Coverage 94.71% 94.73% +0.02%
==========================================
Files 94 94
Lines 13663 13726 +63
==========================================
+ Hits 12941 13004 +63
Misses 722 722
🚀 New features to boost your workflow:
|
| 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] |
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
There was a problem hiding this comment.
Yes, this was a bug. It's now fixed in 9c2b182.
|
thank you for this! would you mind implementing the same behavior for a synchronous method ( |
…reads Add _decode_partial_sync so FusedCodecPipeline reads only the needed rows of an uncompressed chunk, sharing the decode step with the async method. Decide what a store sent for a range request by its exact length: the requested range, the whole chunk, or everything from the range start. Any other length raises instead of returning wrong data. Run the partial read tests on both codec pipelines and add a changelog entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Done in 9c2b182. |
|
this is great, thank you. one wrinkle that needs to be fixed in documentation: prior to this change, broken chunks (e.g., truncated due to an aborted write) would cause an error at indexing time. now, array indexing will not necessarily error on a broken chunk, if the region requested is locally valid. That's fine, but we should document this. I'll handle that in a follow-up PR. |
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/