Repository navigation
Conversation
…l value Creating a sharded array failed when the inner codec chain could not encode the data type's default scalar, e.g. a `scale_offset` filter that maps only a subrange of the data type, even when the array's own fill value encodes fine (zarr-developers#4511). `ShardingCodec.validate` probed the inner chain with `dtype.default_scalar()`, since `validate` never receives the fill value. Run the inner-chain check from `ShardingCodec.evolve_from_array_spec` instead, which receives the threaded spec: each inner codec is evolved, validated and resolved against the spec the codecs before it leave, including the fill value as those codecs encode it. An array whose fill value the inner chain cannot encode is still rejected, because an unwritten chunk holds the fill value. Also drop the per-codec `validate` loop from `ArrayV3Metadata._validate_metadata`. `__init__` has already validated each codec against the threaded spec; the loop re-validated them against the array's own data type, which rejected valid chains such as int16 -> `cast_value` float32 -> `scale_offset` with a scale of 0.5. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Draw array documents from zarr-metadata's hypothesis strategies and hand each to `ArrayV3Metadata.from_dict`. zarr-python may refuse a valid document only for a fill value its codecs cannot encode, and must then refuse it too with each shard's codecs moved out of the shard. Two slices run: every definition, and the integer/float data types with the value-transforming codecs, where fill value refusals are common. Before this branch's fix the property fails for both bugs it fixes: the unthreaded re-validation in `_validate_metadata`, and the sharding probe with the data type's default scalar. Known divergences are left out of the draw where possible and each is pinned by a strict xfail test: object-spelled data types, `r*` raw bits, integer-array `bytes` fill values, sharding behind `transpose`, hex `cast_value` scalar map values, and zarr-metadata accepting empty rectilinear edge lists (barred since zarr-extensions#78). Adds `zarr-metadata[testing]==0.8.0` to the test dependency group. Assisted-by: ClaudeCode:claude-opus-5-5
…deps The conformance test exhausted memory on CI: zarr-python expands each run-length pair of rectilinear edges into a list, and zarr-metadata draws runs of up to millions of chunks. Draw no grid listing more than 10,000 chunks along an axis, and pin the divergence with a strict xfail test. The min_deps env could not resolve: zarr-metadata 0.8.0 needs typing-extensions>=4.16, and min_deps pins 4.14. Move zarr-metadata into its own `conformance` dependency group, which the test envs include and min_deps does not, and skip the module where it is not installed. Assisted-by: ClaudeCode:claude-opus-5-5
…ed chunk grid `ArrayV3Metadata` validated every codec against the stored chunk grid, even after a `TransposeCodec` filter had permuted the chunk shape. A sharding serializer whose inner chunk shape divided only the stored grid was accepted and then wrote data that read back wrong; one that divided the chunks it actually receives was rejected. Codecs gain a `resolve_chunk_grid` hook, the grid counterpart of `resolve_metadata`, which defaults to the identity. `TransposeCodec` permutes the grid's dimensions with it, moving a rectilinear grid's edge lists with their dimensions. Array metadata threads the grid through the codecs alongside the spec, and drops the second, unthreaded validate loop. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-value' into claude/compassionate-bun-956ef7 # Conflicts: # src/zarr/core/metadata/v3.py
…does not divide Validation runs when a stored array is opened, so checking that a sharding codec's inner chunk shape divides its shards in `ShardingCodec.validate` made such arrays, and every group holding one, unopenable. Older versions stored them: a transposed shard that the inner chunk shape divides only untransposed, or a nested sharding codec. The check moves to `ShardingCodec.check_chunk_grid`, which `ArrayV3Metadata.to_buffer_dict` runs (via `check_shard_chunk_grids`) on the grid each sharding codec receives, so such metadata is still never stored. Reading or writing such a shard now raises in `_get_chunks_per_shard` instead of returning data from the wrong place or dropping data. The zarr-metadata conformance test no longer excludes sharding behind a transpose, which the merged transpose fix reads correctly. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The divisibility check left `ShardingCodec.validate`, so the rectilinear grid tests call `check_chunk_grid`. Creating an array after a transpose now warns about partial reads before its metadata is refused, as the round-trip test already expects. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lity Review fixes for the stored-array opening change: - `_check_chunk_grid` no longer compares an inner chunk shape with a grid of another number of dimensions (a filter such as `PackBits` that flattens chunks without declaring its grid). It compared dimension 0 only, which refused `PackBits` followed by a sharding codec whose inner chunk shape divides the flattened shard. Reading or writing checks the shard itself. - `TransposeCodec.resolve_chunk_grid` returns such a grid unchanged instead of raising `IndexError` when the array is opened. - The shard checks are private (`_check_chunk_grid`, `_check_shard_chunk_grids`) rather than new public API. - Docstrings no longer claim checks that moved, and say that a group's consolidated metadata is not checked. - Tests: a codec after a transpose is validated against the transposed grid; `PackBits` followed by sharding round-trips; the conformance test for sharding behind a transpose stores the metadata, so it fails without the transpose fix. - The changelog splits the new `resolve_chunk_grid` hook into a feature fragment. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store-time shard check read shard shapes from `resolve_chunk_grid`, whose default leaves the grid unchanged even for a codec whose `resolve_metadata` changes the chunk shape. Behind `PackBits` it refused valid shards (a nested sharding codec that `main` accepts) and stored metadata whose shards it could tell were indivisible. `_check_shards` now passes a chunk spec through `resolve_metadata`, as reading and writing do. A regular grid's shards and every shard's inner chunks are checked against that spec, exactly for any codec. Only the shards of a rectilinear grid, whose shapes differ, are checked against the grid. The zarr-metadata conformance property now also stores each document it reads, so it covers the store-time check. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A codec that changes the shape of a chunk without declaring its grid (`PackBits`) leaves the rectilinear grid describing unpacked chunks. The store-time check compared those edges with the inner chunk shape and refused a valid 1-D array whose packed shards the inner chunks divide. `_check_shards` now checks the grid only while its first chunk matches the threaded chunk spec, which also replaces the dimension-count guard in `_check_chunk_grid`; reading or writing checks a stale grid's shards. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A codec whose output's number of dimensions depends on the chunk shape (such as one that drops axes of length 1) can leave the shards with another number of dimensions than the inner chunk shape, which validation against the array's shape does not see. Storing such metadata raised a bare `zip()` error. `_check_shards` now refuses it with an explanation, and reading or writing such a shard raises the shard error. A stale rectilinear grid now checks the first shard, whose shape the spec gives exactly, instead of nothing. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reading or writing a shard whose shape has another number of dimensions than the inner chunk shape now says so, instead of calling the shapes indivisible. A test covers the first-shard check of a rectilinear grid that `PackBits` left stale. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An inner chunk size of 12 divides the stale grid's edge of 96 but not the 13-byte first shard, so the test fails if the stale grid is checked. Assisted-by: ClaudeCode:claude-opus-5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🤖 AI text below 🤖 The agent merged #446 into this branch and changed how a sharding codec's inner chunk shape is checked, so that arrays already stored with an indivisible inner chunk shape open again. The check that the inner chunk shape divides each shard moved out of Stack: this PR now contains #446 (upstream zarr-developers#4633) and should merge after it. It stays a draft until #446 merges and What changed since the previous head (4528fc7)
Behavior on a store that
Tests
Adversarial review record (6 rounds, fresh reviewer agents)Round 1 (3 reviewers: correctness, compatibility, design/tests)
Round 2 (2 reviewers)
Round 3: no serious finding. Minor: a rectilinear grid left stale by Round 4
Round 5: no serious finding. Minor:
Round 6: no serious finding. The rectilinear test did not pin which shard is checked: fixed in eccbae5. Follow-ups not in this PR
|
…-test-gap-397442 # Conflicts: # uv.lock
main now accepts a `bytes` fill value written as an array of integers (zarr-developers#4493), so its strict xfail passed. Remove the test and the base64-only fill value strategy, so the property draws both spellings again. Assisted-by: ClaudeCode:claude-opus-5-5
…developers#4690) Bumps the python-dependencies group with 9 updates: | Package | From | To | | --- | --- | --- | | [packaging](https://github.com/pypa/packaging) | `26.3` | `26.4` | | [universal-pathlib](https://github.com/fsspec/universal_pathlib) | `0.3.10` | `0.3.11` | | [coverage](https://github.com/coveragepy/coveragepy) | `7.17.3` | `7.17.5` | | [hypothesis](https://github.com/HypothesisWorks/hypothesis) | `6.170.15` | `6.170.17` | | [uv](https://github.com/astral-sh/uv) | `0.13.9` | `0.13.10` | | [moto[s3,server]](https://github.com/getmoto/moto) | `5.2.5` | `5.2.6` | | [mkdocs-material[imaging]](https://github.com/squidfunk/mkdocs-material) | `9.8.1` | `9.8.2` | | [markdown-exec[ansi]](https://github.com/pawamoy/markdown-exec) | `1.13.0` | `1.14.0` | | [ruff](https://github.com/astral-sh/ruff) | `0.17.5` | `0.17.6` | Updates `packaging` from 26.3 to 26.4 - [Release notes](https://github.com/pypa/packaging/releases) - [Changelog](https://github.com/pypa/packaging/blob/main/CHANGELOG.rst) - [Commits](pypa/packaging@26.3...26.4) Updates `universal-pathlib` from 0.3.10 to 0.3.11 - [Release notes](https://github.com/fsspec/universal_pathlib/releases) - [Changelog](https://github.com/fsspec/universal_pathlib/blob/main/CHANGELOG.md) - [Commits](fsspec/universal_pathlib@v0.3.10...v0.3.11) Updates `coverage` from 7.17.3 to 7.17.5 - [Release notes](https://github.com/coveragepy/coveragepy/releases) - [Changelog](https://github.com/coveragepy/coveragepy/blob/main/CHANGES.rst) - [Commits](coveragepy/coveragepy@7.17.3...7.17.5) Updates `hypothesis` from 6.170.15 to 6.170.17 - [Release notes](https://github.com/HypothesisWorks/hypothesis/releases) - [Commits](HypothesisWorks/hypothesis@v6.170.15...v6.170.17) Updates `uv` from 0.13.9 to 0.13.10 - [Release notes](https://github.com/astral-sh/uv/releases) - [Changelog](https://github.com/astral-sh/uv/blob/main/CHANGELOG.md) - [Commits](astral-sh/uv@0.13.9...0.13.10) Updates `moto[s3,server]` from 5.2.5 to 5.2.6 - [Release notes](https://github.com/getmoto/moto/releases) - [Changelog](https://github.com/getmoto/moto/blob/master/CHANGELOG.md) - [Commits](getmoto/moto@5.2.5...5.2.6) Updates `mkdocs-material[imaging]` from 9.8.1 to 9.8.2 - [Release notes](https://github.com/squidfunk/mkdocs-material/releases) - [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG) - [Commits](squidfunk/mkdocs-material@9.8.1...9.8.2) Updates `markdown-exec[ansi]` from 1.13.0 to 1.14.0 - [Release notes](https://github.com/pawamoy/markdown-exec/releases) - [Changelog](https://github.com/pawamoy/markdown-exec/blob/main/CHANGELOG.md) - [Commits](pawamoy/markdown-exec@1.13.0...1.14.0) Updates `ruff` from 0.17.5 to 0.17.6 - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.17.5...0.17.6) --- updated-dependencies: - dependency-name: packaging dependency-version: '26.4' dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python-dependencies - dependency-name: universal-pathlib dependency-version: 0.3.11 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: coverage dependency-version: 7.17.5 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: hypothesis dependency-version: 6.170.17 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: uv dependency-version: 0.13.10 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: moto[s3,server] dependency-version: 5.2.6 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: mkdocs-material[imaging] dependency-version: 9.8.2 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies - dependency-name: markdown-exec[ansi] dependency-version: 1.14.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: python-dependencies - dependency-name: ruff dependency-version: 0.17.6 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: python-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
) Bumps the actions group with 2 updates: [CodSpeedHQ/action](https://github.com/codspeedhq/action) and [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action). Updates `CodSpeedHQ/action` from 5.6.3 to 5.8.0 - [Release notes](https://github.com/codspeedhq/action/releases) - [Changelog](https://github.com/CodSpeedHQ/action/blob/main/CHANGELOG.md) - [Commits](CodSpeedHQ/action@af75f77...b1f28b5) Updates `zizmorcore/zizmor-action` from 0.8.1 to 0.9.2 - [Release notes](https://github.com/zizmorcore/zizmor-action/releases) - [Commits](zizmorcore/zizmor-action@45d7276...1b4550e) --- updated-dependencies: - dependency-name: CodSpeedHQ/action dependency-version: 5.8.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions - dependency-name: zizmorcore/zizmor-action dependency-version: 0.9.2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
…-test-gap-397442 # Conflicts: # uv.lock
zarr-metadata 0.9.0 refuses an empty list of rectilinear edge lengths (zarr-developers#4636), so the strict xfail that pinned the difference passed. Remove it and the exclusion. Assisted-by: ClaudeCode:claude-opus-5-5
A filter that flattens each chunk (numcodecs.packbits) hands a 1-d shard to the sharding codec, which checks its inner chunk shape against the array's own N-d chunk grid. Dropping the second validation loop from `_validate_metadata` let such an array through, and it lost the end of each chunk. Refuse it, as main does. Replace the conformance test's oracle. It accepted any ValueError raised below `resolve_metadata`, so a codec that refused every fill value went unseen. The test now encodes a chunk that holds the fill value and requires zarr-python to refuse the document if and only if that fails. Draw 2000 examples, because the profiles' 300 missed both bugs this branch fixes under the derandomized ci profile. Draw every spelling, and simplify only the data types. Run the test in the slow Hypothesis recipe. Assisted-by: ClaudeCode:claude-opus-5-5
A chunk grid whose rank differs from the shape reached the sharding codec's rank check first, which blamed the shard. Check the grid against the shape before the codec loop, and name ranks in the shard message. Assisted-by: ClaudeCode:claude-opus-5-5
…s#4633) into fix/transpose-chunk-grid-validation Keep this branch's shard checks, which use the chunk grid the codecs before the shard leave, in place of zarr-developers#4633's rank guard against the array's own grid: a 2-d array whose packbits filter feeds a 1-d shard that divides the packed chunk is valid. Drop zarr-developers#4633's rank test, which test_sharding_after_flattening_ filter_indivisible[2d] covers. Take zarr-developers#4633's fill-value oracle for the conformance test, checking storage as well as reading, with the sharding behind transpose divergence removed. Assisted-by: ClaudeCode:claude-opus-5-5
🤖 AI text below 🤖
Fix array metadata validating each codec against the stored chunk grid even after a
TransposeCodecfilter had permuted the chunk shape. A sharding serializer whose inner chunk shape divided only the stored grid was accepted, then read back wrong data. A valid one was rejected. Codecs gain aresolve_chunk_gridmethod, the chunk-grid counterpart ofresolve_metadata, whichTransposeCodecuses to permute the grid.Summary
Repro on upstream main (95ec04a): shape (12, 40), chunks (6, 20),
filters=[TransposeCodec(order=(1, 0))].ShardingCodec(chunk_shape=(3, 10))was accepted. The sharding codec receives (20, 6) chunks, and writing then reading back returned different data (np.array_equalwas False).ShardingCodec(chunk_shape=(10, 3)), which is valid, was rejected with "Chunk edge length 6 in dimension 0 is not divisible by the shard's inner chunk size 10."Fix:
BaseCodec.resolve_chunk_grid(chunk_grid) -> ChunkGridMetadatais a new hook, the grid counterpart ofresolve_metadata. By default it returns the grid unchanged, which is correct for any codec that keeps a chunk's shape. The publicCodec.validatesignature does not change, so third-party codecs are unaffected.TransposeCodec.resolve_chunk_gridpermutes the grid's dimensions byorder, asresolve_metadatapermutes the shape.ArrayV3Metadata.__init__passes the grid through the codecs alongside the spec, so each codec is validated against the grid that the codecs before it leave._validate_metadatano longer runs its second codec validate loop, which ignored the earlier codecs. It also now runs before the codec loop, so an ndim mismatch between the grid and the shape is reported as such instead of surfacing inside a codec.docs/user-guide/extending.mdlists the new hook.Design: why a hook, and how rectilinear grids work
For a regular grid, the grid could be derived generically by passing the chunk shape through
resolve_metadata. Rectilinear grids rule that out. A transpose moves each dimension's edge list, and for a square array with different edge lists per dimension, nothing inresolve_metadata's output shows which dimension moved where. Only the codec knows its permutation, so the codec owns the mapping. Under a transpose, rectilinear edge lists (and bare-int dimensions) move with their dimensions.A third-party codec that changes chunk shape but does not override the hook keeps the behavior from before this PR, so it is no worse off.
The pipeline-level
CodecPipeline.validatemethods incodec_pipeline.pystill loop without passing the grid through, but nothing in the codebase calls them. They are out of scope here.Tests
test_sharding_after_transposeis one parametrized success test. It covers a regular grid, a regular grid transposed twice (a control), a 3-D non-self-inverse order, a rectilinear grid on a square array, and a rectilinear grid with a bare-int dimension. Each case writes and reads data back.test_sharding_after_transpose_indivisiblecovers the single error case, an inner chunk shape that divides the stored grid but not the transposed one, for regular and rectilinear grids.Stack notes
ShardingCodec.evolve_from_array_specand also drops_validate_metadata's validate loop. Expect a small conflict insrc/zarr/core/metadata/v3.pywhichever PR merges second. The resolution keeps the loop in__init__that passes the grid through.🤖 Generated with Claude Code