Repository navigation
Conversation
The new lazy_indexing_asyncio example plans reads with `LazyArray.parts()` and performs every read itself, with `asyncio.gather` over `zarr.AsyncArray`. A part whose `source_selection` Zarr accepts is fetched with it; any other part (a new axis, a negative step, a gather) fetches the ascending cover from `IndexTransform.decompose()` and reads the residual from the block with `numpy_reader`. A cache of decoded chunks, keyed by each chunk's origin and read with `chunk_local_selection`, lets overlapping views share fetches. A reader that refuses every read and a store that counts chunk reads check that the consumer did all the I/O. The example is a plain PEP 723 script run from `main()`, and `tests/test_doc_examples.py` runs it in process, skipping without zarr. Assisted-by: ClaudeCode:claude-opus-5-5
…guide A new section explains how a consumer with its own I/O layer plans with `parts()` and reads each part itself: `Partition.source_selection` where the conservative lowering spells the read, and the cover and residual of `IndexTransform.decompose()` where it refuses. It covers `chunk_local_selection` and `projection.chunk_domain` for chunk caches, backends narrower than NumPy, and links the asyncio example and `zarr_indexing.iteration`. An executable snippet reads a box and a gather without touching the wrapped source. Assisted-by: ClaudeCode:claude-opus-5-5
Review found two bugs in the example's `ChunkCache`. Keyed by the chunk's origin alone, a view partitioned with a different grid read a cached chunk of the wrong extent and got silently wrong values; the cache now keys by the whole `projection.chunk_domain`. Gathering the shared fetch tasks directly meant cancelling one read cancelled fetches other reads awaited, and left the cancelled tasks cached; the fetches are now shielded. The README and guide also say that only queries of more than one coordinate refuse `source_selection`, that the first scenario reads once per part rather than once per chunk, and that the whole domain is the cache key. Assisted-by: ClaudeCode:claude-opus-5-5
Rewrap the guide's new opening sentence, and say that views indexed from one `LazyArray` share a grid; `with_parts()` also derives a view, with a different one. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
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.
🤖 AI text below 🤖
A new
lazy_indexing_asyncioexample plans reads withLazyArray.parts()and fetches them through its own asyncio code overzarr.AsyncArray, including a chunk cache that overlapping views share. The integrations guide gains a section on consumer-owned I/O withPartition.source_selectionandIndexTransform.decompose().Stacked on #496 (public basic-selection lowering), which must merge first; this PR targets its branch and stays a draft until then. Re-cut from #292 (piece 3 of 3). #292's
result_intowas dropped because it overlaps upstream'siter_filled.Agent notes
What the example does. The planner is
LazyArray(source).with_reader(RefuseReads()), so any read through the wrapper fails. All data comes from the consumer's ownasyncio.gatheroverzarr.AsyncArray.getitem. ACountingStoreasserts the I/O. Five views read one request per part: a box, a strided column, an added axis, reversed strides and a gather, totaling 42 chunk reads for 42 parts. A shared chunk cache then serves three overlapping views with 12 chunk reads.source_selectionZarr accepts is fetched with it. Any other part (an added axis, a negative step, a gather) fetches the ascending cover fromdecompose()and applies the residual in memory withnumpy_reader.read_into.asyncio.Tasks keyed by the wholeprojection.chunk_domainand shields fetches, so one cancelled read doesn't cancel the others.zarr_indexing.iteration: those functions read through the wrapper's own reader, andSelectionPlan.chunkskeys are opaque, so they can't drive the consumer's own fetches. The README and guide point to iteration for when the wrapper's reader can do the I/O.Changes from #292's version.
.lazy[...]becomesview[...](upstream feat(indexing): make LazyArray indexing lazy by default zarr-developers/zarr-python#4350).main(), with only anEXAMPLE_REQUIRESentry intest_doc_examples.py.async defs became module-level functions.as_basic_selectionrefuses conservatively,decomposerefuses only negative coordinates, Zarr rejectsNoneand negative steps, anddecompose_unit_stepis documented.Verification.
just test: 2117 passed, 48 skipped (tensorstore, dask and xarray not installed). The example's tests: 5 passed. The example also ran as its README says, with PEP 723 deps from PyPI and withzarr==3.1.0. Typecheck has 0 errors, lint and format are clean, andjust docs-check(strict) builds. Not type-checked:examples/is outside pyright's include, like the other examples.Adversarial review. Three rounds by fresh reviewer agents.
chunk_domain.inclusive_min, so a view on a different grid silently read a chunk of the wrong extent. It is now keyed by theIndexDomain.asyncio.shield.recorder.keys == []check.Noted for #496, outside this diff: the
Partition.boxdocstring says the box "may be narrower thanprojection.chunk_domain", butparts()buildsboxfromchunk_domain.🤖 Generated with Claude Code