Repository navigation
Conversation
The cover-and-residual factorization is a property of a transform, not of a reader: `reader.py` and `iteration.py` both consume it. Move `_decompose_basic`, `_decompose_unit_step` and their helpers into `transform.py` unchanged, so the next commit can give them a public owner. Assisted-by: ClaudeCode:claude-opus-5-5
Add `IndexTransform.as_basic_selection`, which spells a box transform as the tuple of ints, slices and `None` that reads the same cells under NumPy basic indexing, and refuses everything else with the new `NoBasicSelectionError` (a `ValueError`). Fabricated axes lower back to the `None` that made them. Add `IndexTransform.decompose` and `decompose_unit_step`, the total counterparts: every transform factors into ascending cover slices plus an in-memory residual. They are the former private `_decompose_basic` and `_decompose_unit_step`, now the one implementation behind the built-in readers and `iteration`. Both refuse a negative output coordinate, which NumPy would count from the end of the source. `BasicSelection` names the lowering's output type. Assisted-by: ClaudeCode:claude-opus-5-5
Add `Partition.source_selection`, the basic selection on the raw wrapped array that reads a part, and `Partition.chunk_local_selection`, the same read relative to the part's grid cell. A consumer that plans with `parts()` but fetches through its own I/O layer can assemble a view as `out[part.out_selection] = source[part.source_selection]`, or read a cached decoded cell with `cell[part.chunk_local_selection]`. Query parts, and boxes with no basic spelling, raise `NoBasicSelectionError`. Both are thin lowerings of `part.view.transform` and `part.projection.chunk_transform`, which already address the source and the cell in global and cell-local coordinates respectively. Assisted-by: ClaudeCode:claude-opus-5-5
… machine `ChainedIndexingStateMachine` gains a `fabricates_an_axis` rule, drawing from the new `newaxis_selections` strategy, so views with axes no source axis backs are reached at full weight. A new invariant runs the consumer-owned-I/O assembly literally: every part's `source_selection` and `chunk_local_selection` must reproduce the model under plain NumPy, query and degenerate parts must refuse both spellings, and every part must obey the `decompose` factorization law. `ProjectionReader` reads through a part's projection instead of its transform, gathering from the whole grid cell; the machine always draws it alongside `basic_reader`, so both halves of a `ReadContext` are checked. Assisted-by: ClaudeCode:claude-opus-5-5
Indexing a rank-0 cell with the empty tuple returns its one value however many points repeat it, so a broadcast of a 0-d source failed to reshape. Broadcast to one value per point. Also list transform-key transposes among the boxes `Partition.source_selection` refuses. Found by the adversarial review of this branch. Assisted-by: ClaudeCode:claude-opus-5-5
Review follow-ups: say that as_basic_selection also refuses some degenerate transforms NumPy could spell, that decompose checks negative coordinates even on empty domains, how to apply a decompose residual with public API, and that BasicSelection differs from zarr's type of the same name. Pin the empty fabricated-axis refusal with a test. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
This was referenced Dec 4, 2026
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 🤖
IndexTransform.as_basic_selection()converts a transform to the NumPy basic selection (ints, slices andNone) that reads the same cells, and raises the newNoBasicSelectionErrorwhen it can't.IndexTransform.decompose()anddecompose_unit_step()split any transform into ascending slices to fetch plus an in-memory remainder, andPartition.source_selection/Partition.chunk_local_selectiongive each part's read as a basic selection, so code that plans withparts()can fetch through its own I/O layer.Re-cut from #292 (piece 1 of 3: public lowering). #292's part-view projection design is superseded by zarr-developers#4349 and is not carried. Its
result_intoand asyncio example are not in this PR; #292 stays open until those are decided.Agent notes
Public names added
zarr_indexing.BasicSelection:tuple[int | slice | None, ...], NumPy's basic-indexing dialect. Distinct fromzarr.core.indexing.BasicSelection, which admitsEllipsis.zarr_indexing.NoBasicSelectionError(aValueError): the transform has no basic spelling the lowering accepts.IndexTransform.as_basic_selection(): conservative and partial. It refuses ArrayMaps, stride 0, transposed or repeated axes, unreferenced non-singleton axes and negative coordinates, plus a few degenerate shapes NumPy could spell (transposed or broadcast axes of extent 0 or 1). A fabricated axis lowers toNone.IndexTransform.decompose()/decompose_unit_step(): total factorization into(ascending cover slices, residual transform). These are main's privatereader._decompose_basic/_decompose_unit_step, moved, not copied.reader.pyanditeration.py(from feat(zarr-indexing): read many selections, loading each shared chunk once zarr-developers/zarr-python#4691) now call the public methods, so there is still one implementation. A residual is applied with public API asnumpy_reader.read_into(block, ReadContext(residual), out).Partition.source_selection(global coordinates) andPartition.chunk_local_selection(cell-local coordinates).zarr_indexing.testing:ProjectionReaderand thenewaxis_selectionsstrategy.How it composes with
iteration.py. Iteration is the scheduling layer: it shares chunks across selections, prefetches and fills destinations. For each chunk it applies exactlypart.projection.chunk_transform.decompose(). This PR makes that step public for consumers who own their I/O. Not done here: such consumers still can't reuse iteration's cross-selection chunk sharing, because its per-chunk pieces are private. Exposing them onSelectionPlanwould be a separate PR.One behavior change.
decomposeraisesNoBasicSelectionErroron a negative output coordinate, where readers used to let NumPy wrap it. No path fromLazyArray, the readers or iteration reaches it:composebounds-checksIndexTransformkeys, empty reads make no reader calls, and iteration works in chunk-local coordinates. Only a direct reader call with a hand-built transform is affected.Left out of #292. The
_window/_projectionplumbing, the 5 projection-pairing tests and the window-narrowing state-machine steps, all superseded by zarr-developers#4349. Also left out:result_into(it overlapsiter_filled), the asyncio example, and #292's packaging tweaks and fragments. #292's two runtimeasserts and a nested function withnonlocalwere removed by restructuring.Verification.
just test: 2112 passed, 48 skipped (dask, xarray and tensorstore not installed).just test-tensorstore: 230 passed.just typecheck: 0 errors, the same warning counts as main.just lintis clean.just docs-check(mkdocs --strict) builds.Adversarial review, two rounds by fresh reviewer agents, neither serious:
ProjectionReaderfailed on rank-0 cells read at several points. Fixed in 07e69ec.source_selectiondocstring missed theIndexTransform-key transpose refusal. Fixed in 07e69ec.LazyArraychains including rectilinear grids and partitions of partitions, anddecomposecompared against main on 20,000 transforms. Its minor findings were all addressed in bc4eb48:numpy_reader.read_intois now named in the docstring.BasicSelectionname collision is noted. Nits not acted on: the guide's "cover" wording, readerread_intodocs, theProjectionReaderexport, and a theoretical 64-dimension limit in the state machine.🤖 Generated with Claude Code