Skip to content

Commit eb9a6e7

Browse files
committed
feat: add the zarr-indexing package (TensorStore-style index transforms)
Standalone workspace package extracted from the lazy-indexing branch (zarr-developers#3906): composable, lazy coordinate transforms (IndexTransform / IndexDomain / output maps), dependency-aware chunk resolution against a DimensionGridLike protocol, and an ndsel-conformant JSON wire format validated against the vendored conformance corpus. zarr itself does not depend on zarr-indexing yet — the runtime wiring lands separately once 0.1.0 is published. The package is numpy-only; its tests exercise chunk resolution against zarr's concrete ChunkGrid, so they run from the workspace root (uv sync --all-packages). Assisted-by: ClaudeCode:claude-fable-5
1 parent ff17c7e commit eb9a6e7

40 files changed

Lines changed: 6254 additions & 0 deletions

‎.github/workflows/check_changelogs.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ jobs:
2929

3030
- name: Check zarr-metadata changelog entries
3131
run: uv run --no-sync python ci/check_changelog_entries.py packages/zarr-metadata/changes
32+
33+
- name: Check zarr-indexing changelog entries
34+
run: uv run --no-sync python ci/check_changelog_entries.py packages/zarr-indexing/changes
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: zarr-indexing release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'zarr_indexing-v*'
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
build:
18+
name: Build wheel and sdist
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash
23+
working-directory: packages/zarr-indexing
24+
steps:
25+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
26+
with:
27+
persist-credentials: false
28+
fetch-depth: 0 # hatch-vcs needs full history + tags
29+
30+
- name: Install Hatch
31+
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
32+
with:
33+
version: '1.16.5'
34+
35+
- name: Build
36+
run: hatch build
37+
38+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
39+
with:
40+
name: zarr-indexing-dist
41+
path: packages/zarr-indexing/dist
42+
43+
test_artifacts:
44+
name: Test built artifacts
45+
needs: [build]
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
49+
with:
50+
name: zarr-indexing-dist
51+
path: dist
52+
53+
- name: Install uv
54+
uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2
55+
with:
56+
enable-cache: false
57+
58+
- name: Set up Python
59+
run: uv python install 3.12
60+
61+
- name: Install built wheel and run import smoke test
62+
run: |
63+
wheel=$(ls dist/*.whl)
64+
uv run --with "${wheel}" --python 3.12 --no-project \
65+
python -c "import zarr_indexing; print('zarr_indexing', zarr_indexing.__version__)"
66+
67+
upload_pypi:
68+
name: Upload to PyPI
69+
needs: [build, test_artifacts]
70+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/zarr_indexing-v')
71+
runs-on: ubuntu-latest
72+
environment:
73+
name: zarr-indexing-releases
74+
url: https://pypi.org/p/zarr-indexing
75+
permissions:
76+
id-token: write # required for OIDC trusted publishing
77+
attestations: write # required for artifact attestations
78+
steps:
79+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
80+
with:
81+
name: zarr-indexing-dist
82+
path: dist
83+
84+
- name: Generate artifact attestation
85+
uses: actions/attest@f7c74d28b9d84cb8768d0b8ca14a4bac6ef463e6 # v4.2.0
86+
with:
87+
subject-path: dist/*
88+
89+
- name: Publish package to PyPI
90+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
91+
92+
upload_testpypi:
93+
name: Upload to TestPyPI
94+
needs: [build, test_artifacts]
95+
if: github.event_name == 'workflow_dispatch'
96+
runs-on: ubuntu-latest
97+
environment:
98+
name: zarr-indexing-releases-test
99+
url: https://test.pypi.org/p/zarr-indexing
100+
permissions:
101+
id-token: write
102+
attestations: write
103+
steps:
104+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
105+
with:
106+
name: zarr-indexing-dist
107+
path: dist
108+
109+
- name: Generate artifact attestation
110+
uses: actions/attest@f7c74d28b9d84cb8768d0b8ca14a4bac6ef463e6 # v4.2.0
111+
with:
112+
subject-path: dist/*
113+
114+
- name: Publish package to TestPyPI
115+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
116+
with:
117+
repository-url: https://test.pypi.org/legacy/
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: zarr-indexing
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'packages/zarr-indexing/**'
8+
- '.github/workflows/zarr-indexing.yml'
9+
pull_request:
10+
paths:
11+
- 'packages/zarr-indexing/**'
12+
- '.github/workflows/zarr-indexing.yml'
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: read
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
test:
24+
name: pytest py=${{ matrix.python-version }}
25+
runs-on: ubuntu-latest
26+
defaults:
27+
run:
28+
shell: bash
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
python-version: ['3.12', '3.13', '3.14']
33+
steps:
34+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
35+
with:
36+
persist-credentials: false
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
39+
with:
40+
enable-cache: true
41+
- name: Set up Python ${{ matrix.python-version }}
42+
run: uv python install ${{ matrix.python-version }}
43+
# The transform tests exercise chunk resolution against zarr's ChunkGrid,
44+
# so they run from the repo root against the full workspace (which installs
45+
# both `zarr` and the `zarr-indexing` workspace member) rather than in
46+
# package isolation.
47+
- name: Sync test dependency group
48+
run: uv sync --all-packages --group test --python ${{ matrix.python-version }}
49+
- name: Run pytest
50+
run: uv run --no-sync --group test pytest packages/zarr-indexing/tests
51+
52+
ruff:
53+
name: ruff
54+
runs-on: ubuntu-latest
55+
defaults:
56+
run:
57+
shell: bash
58+
working-directory: packages/zarr-indexing
59+
steps:
60+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
61+
with:
62+
persist-credentials: false
63+
- name: Install uv
64+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
65+
- name: Run ruff
66+
run: uvx ruff check .
67+
68+
pyright:
69+
name: pyright
70+
runs-on: ubuntu-latest
71+
defaults:
72+
run:
73+
shell: bash
74+
working-directory: packages/zarr-indexing
75+
steps:
76+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
77+
with:
78+
persist-credentials: false
79+
- name: Install uv
80+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
81+
with:
82+
enable-cache: true
83+
- name: Set up Python
84+
run: uv python install 3.12
85+
- name: Sync test dependency group
86+
run: uv sync --group test --python 3.12
87+
- name: Run pyright
88+
run: uv run --group test --with pyright pyright src
89+
90+
zarr-indexing-complete:
91+
name: zarr-indexing complete
92+
needs: [test, ruff, pyright]
93+
if: always()
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Check failure
97+
if: |
98+
contains(needs.*.result, 'failure') ||
99+
contains(needs.*.result, 'cancelled')
100+
run: exit 1
101+
- name: Success
102+
run: echo Success!
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release notes
2+
3+
<!-- towncrier release notes start -->

‎packages/zarr-indexing/LICENSE.txt‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015-2025 Zarr Developers <https://github.com/zarr-developers>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎packages/zarr-indexing/README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# zarr-indexing
2+
3+
Composable, lazy coordinate transforms for Zarr array indexing.
4+
5+
This package implements TensorStore-inspired index transforms. The core idea:
6+
every indexing operation (slicing, fancy indexing, etc.) produces a coordinate
7+
mapping from user space to storage space. These mappings compose lazily — no
8+
I/O until you explicitly read or write.
9+
10+
Key types:
11+
12+
- `IndexDomain` — a rectangular region of integer coordinates
13+
- `IndexTransform` — maps input coordinates to storage coordinates
14+
- `ConstantMap`, `DimensionMap`, `ArrayMap` — the three ways a single output
15+
dimension can depend on the input
16+
- `compose` — chain two transforms into one
17+
18+
The package depends only on NumPy and the standard library; it does not import
19+
`zarr`. It is developed in the [zarr-python](https://github.com/zarr-developers/zarr-python)
20+
repository and consumed by `zarr` to resolve array indexing operations.
21+
22+
## Installation
23+
24+
```bash
25+
pip install zarr-indexing
26+
```
27+
28+
## License
29+
30+
MIT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reworked the JSON layer to conform to the [ndsel](https://github.com/d-v-b/ndsel) draft wire format, which adapts TensorStore's `IndexTransform`. A new `zarr_indexing.messages` module (`parse_ndsel`, `normalize_ndsel`, `NdselError`) is a pure JSON-to-JSON layer that accepts all five message kinds (`point`/`box`/`slice`/`points`/`transform`) and normalizes them to the canonical transform body, enforcing the full ndsel error taxonomy. The package is checked against the vendored, language-agnostic ndsel conformance corpus. `index_transform_to_json`/`index_transform_from_json` (and the domain variants) now produce and consume the canonical body. On serialization, orthogonal (`oindex`) `index_array` maps no longer emit `input_dimension` alongside `index_array` (a combination both ndsel and TensorStore reject), and degenerate all-singleton index arrays collapse to constant maps; the in-memory `input_dimension` is reconstructed from the array's dependency axes on load.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Writing a changelog entry for `zarr-indexing`
2+
-----------------------------------------------
3+
4+
Fragments in **this** directory are release notes for the `zarr-indexing`
5+
package only — kept separate from the parent zarr-python `changes/`
6+
directory so a PR touching only `packages/zarr-indexing/` produces a
7+
release note for this package only.
8+
9+
Please put a new file in this directory named `xxxx.<type>.md`, where
10+
11+
- `xxxx` is the pull request number associated with this entry
12+
- `<type>` is one of:
13+
- feature
14+
- bugfix
15+
- doc
16+
- removal
17+
- misc
18+
19+
Inside the file, please write a short description of what you have
20+
changed, and how it impacts users of `zarr-indexing`.
21+
22+
A `zarr-indexing` release runs `towncrier build` in `packages/zarr-indexing/`,
23+
which consumes the fragments here and updates `CHANGELOG.md`. Fragments
24+
that describe parent zarr-python changes (not the transforms package)
25+
belong in the top-level `changes/` directory, not here.

0 commit comments

Comments
 (0)