feat(zarr-metadata): composition rules layer, shape-exact entity validators, create_* factories - #4379
Draft
d-v-b wants to merge 9 commits into
Draft
feat(zarr-metadata): composition rules layer, shape-exact entity validators, create_* factories#4379d-v-b wants to merge 9 commits into
d-v-b wants to merge 9 commits into
Conversation
… validators return tuples `ZarrV3NamedConfigJSON.name` and `.configuration` are `ReadOnly` and the envelope is `closed`, so the concrete codec / chunk-grid / chunk-key-encoding / data-type TypedDicts are assignable to the fields they describe. Every concrete `*Object` / `*Configuration` is `closed` and object forms declare `must_understand: NotRequired[bool]`. Every `validate_*` in `zarr_metadata.model` returns `tuple[ValidationProblem, ...]`, `MetadataValidationError.problems` is a tuple, and `load_store_json` returns `object` rather than `Any`. `ANN401` is enforced package-wide. `ZarrV2ConsolidatedMetadataJSON.zarr_consolidated_format` is `Literal[1]`. Split from #296 (part 1 of 3). Assisted-by: ClaudeCode:claude-fable-5-1
Assisted-by: ClaudeCode:claude-fable-5-1
…arr-developers#4365's tests Assisted-by: ClaudeCode:claude-opus-5 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…4378 Assisted-by: ClaudeCode:claude-opus-5 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…dators, create_* factories Adds `zarr_metadata.rules`: cross-field judgments over whole documents (fill value vs data type, codec pipeline ordering, chunk-grid geometry, sharding and transpose against the array each codec actually receives, struct field rules, dimension-name counts), registered where they are defined and dispatched per entity; `validate_*` / `is_*` / `parse_*` / `check_*` front doors for readers; `v3._shape` validators derived from the entity TypedDicts; and one `create_*` factory per document TypedDict. The two rank checks (v3 `dimension_names` vs `shape`, v2 `chunks` vs `shape`) move from the structural validator into the rules layer. The pydantic field types now run the rules layer before normalizing, so they are strictly stronger than before rather than weaker. Relative to #296 this drops the incremental builder, the extension-point provenance table, `TypeIs` codec guards, fill-value propagation through codec chains (no rule read it), registry introspection helpers, and a duplicated v2 consolidated envelope check; renames the `.zarray`/`.zgroup` factories to `zarray`/`zgroup`; and requires an endianness on the `bytes` codec inside `index_codecs`. Split from #296 (part 2 of 3). Assisted-by: ClaudeCode:claude-fable-5-1
Assisted-by: ClaudeCode:claude-fable-5-1
Assisted-by: Codex:GPT-6
…eate_* factories Upstream enabled ruff S101 for runtime code (zarr-developers#4363). The six parse-then-raise factories share a _parsed_or_raise helper that narrows the parsed document, and the rule-registration import uses importlib.import_module instead of an assert to keep it referenced. Assisted-by: ClaudeCode:claude-opus-5 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…4379 Assisted-by: ClaudeCode:claude-opus-5 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
d-v-b
force-pushed
the
zarr-metadata/rules-layer
branch
from
September 19, 2026 16:55
7f19f4e to
feffe5c
Compare
Documentation build overview
12 files changed ·
|
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 🤖
Part 2 of a split of d-v-b#296 (reviewed on the fork as d-v-b#318).
Depends on #4378. Cross-fork PRs can't be stacked, so this targets
mainand its diff includes #4378's commits; review only the commits afterchore(zarr-metadata): number changelog fragments for #4378, or the diff against #4378's branch: d-v-b/zarr-python@zarr-metadata/types-and-tuples...zarr-metadata/rules-layerWhat this adds
zarr_metadata.rules: composition judgments over whole documents. Fill value vs data type for every dtype family; codec pipeline ordering (AA* AB BB*, exactly one AB, inconclusive with unknown codecs); known-name configuration shapes;dimension_namescount; chunk-grid values and geometry (regular rank; rectilinear rank and per-dimension sums incl. RLE pairs); transpose orders; sharding (inner pipelines judged recursively, inner chunks positive, rank-matched, and dividing the enclosing chunk); struct field rules. Codec chains are judged against the array each codec receives, so a shard behind a transpose must divide the transposed chunk and abytescodec behind acast_valueneeds an endianness for the target type. Rules are registered where they are defined; rules about one codec, grid, or data type live with that entity underrules._entitiesand are dispatched by name.validate_*/is_*/parse_*/check_*for array and group documents in both formats, structure and composition reported together.check_*returnsValid[T] | Invalid.v3._shape: one exact validator per known entity, key sets derived from the TypedDicts'__annotations__/__required_keys__. Unknown configuration members report as their ownunknown_keykind and never suppress other findings.create_*factories inzarr_metadata.builder, one per public document TypedDict,**kwargs: Unpack[<TypedDict>], one combined raise. The strict on-disk factories arecreate_zarr_v2_zarray_json/create_zarr_v2_zgroup_json.Boundary changes
dimension_namesvsshapeand v2chunksvsshapemove from the structural validator into rules.modelparsers and dataclasses now accept those documents.bytesinside shardingindex_codecsis rejected: the shard index isuint64, so the endianness is required there too.Relative to d-v-b#296
Dropped: the incremental builder, the extension-point provenance table, and
TypeIscodec guards (held back for a later PR); fill-value propagation through codec chains (no rule read it, soArraySpecis two fields andNonereplaces theUNKNOWNsentinel); registry introspection helpers with no non-test consumer; a duplicated v2 consolidated envelope check. README and docs no longer claim the model layer checks dimension counts.Entity rules recursively validate nested data types in struct fields and cast targets. A Hypothesis regression caught invalid datetime/timedelta scale factors inside those positions. Remaining follow-ups: sharding under a rectilinear grid is unjudged; v2 fill-value/dtype consistency has no rule.
Rebased onto main. Main now bans runtime
assert(#4363), so the sixcreate_*factories share a_parsed_or_raisehelper and the rule-registration import usesimportlib.import_module.Verified after rebase: ruff check/format (package and repo root), pyright 1.1.404 (0 errors), 756 package tests.
🤖 Generated with Claude Code