Skip to content

feat(zarr-metadata)!: replace scope update with copy(update=...) and add definitions with union - #427

Draft
d-v-b wants to merge 6 commits into
mainfrom
claude/ecstatic-lamarr-9bd090
Draft

d-v-b wants to merge 6 commits into
mainfrom
claude/ecstatic-lamarr-9bd090

Conversation

@d-v-b

@d-v-b d-v-b commented Oct 29, 2026

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Replace ZarrV3Context.update(**slots) and ZarrV2Context.update(**slots) with copy(*, update=None), after pydantic's model_copy(update=...): context.update(codecs=[...]) becomes context.copy(update={"codecs": [...]}), and still replaces each slot it is given whole. To add definitions to a scope and keep the ones it has, use union: CORE_AND_EXTENSIONS.union(ZarrV3Context(data_types=[MY_DATA_TYPE])), which the docs now show in place of splicing a slot's definitions back in.

Fixes #424.

  • copy's docstring warns that copy(update={"codecs": [X]}) leaves X as the only codec and points at union; the docstrings of union, the scope classes and the definition package overview name union as the way to add definitions.
  • CORE_AND_EXTENSIONS is now built with CORE.union(...). About 50 test call sites moved: splices of a slot's own definitions became union, and replacements by name became copy(update=...).
  • A new test, test_union_adds_definitions_and_keeps_every_one_the_scope_has, covers the case in the issue.
  • The document models (ZarrV3ArrayMetadata and friends) keep their own update(**members), which has the same replace-whole meaning. The agent left them alone, so the two operations now have different names.

just check in packages/zarr-metadata passes: ruff, pyright, the tests on Python 3.11 and the newest supported version, and the strict docs build.

🤖 Generated with Claude Code

d-v-b added 2 commits October 29, 2026 20:08
…add definitions with union

`ZarrV3Context.update(**slots)` and `ZarrV2Context.update(**slots)` read
as a merge, but replace each slot whole, so passing one new definition
silently dropped every default. They become `copy(*, update=None)`,
after pydantic's `model_copy(update=...)`, whose replace-whole meaning
pydantic users already know. Adding definitions is `union`, which keeps
every definition the scope has and refuses a conflicting one; the docs,
docstrings and call sites now use it instead of splicing a slot's
definitions back in.

Fixes #424

Assisted-by: ClaudeCode:claude-opus-5-5
…ts PR

Assisted-by: ClaudeCode:claude-opus-5-5
d-v-b added 4 commits November 4, 2026 09:58
…elopers#4597)

* feat(zarr-metadata): draw nested fields and codec pipelines

Add Hypothesis strategies for struct, cast_value and sharding_indexed,
which draw the fields they hold from the same Strategies mapping, and a
`pipelines` strategy that walks a codec pipeline, drawing each codec for
the chunk the codec before it hands on via its definition's transition.
A shard's inner and index pipelines are drawn for the chunks its
definition's `pipelines` gives. Shards and structs nest at most one
level deep, and strategies are wrapped in a mapping with a short repr so
Hypothesis's error notes stay under its 30,000-character warning.

Every strategy record's functions now take the Strategies mapping as
their last argument.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): reject non-numeric data types in arithmetic codecs

`NOT_NUMBERS` predates the zarr-python data types, so `cast_value` and
`scale_offset` accepted `fixed_length_utf32`, `null_terminated_bytes`,
`raw_bytes` and `variable_length_bytes`, and the strategies drew them.
The cast_value spec defines the codec only for floating-point and
integral data types.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): let the later of two same-named strategies win

`_scope` documented this but raised `ScopeConflictError`, so `declarations`
failed for any definition named as a default, which worked before this
branch. Pipelines and data type names now draw only the definition that
claims a name, and `declarations` reads a draw with its own definition
claiming the name.

Assisted-by: ClaudeCode:claude-opus-5-5

* test(zarr-metadata): check a same-named definition reads its own draws

The test compared a draw with the bare name, which depended on the
example Hypothesis returned and said nothing of which definition read
it. Every spelling is now read by the definition it was drawn for.

Assisted-by: ClaudeCode:claude-opus-5-5

* chore(zarr-metadata): number the nested strategies changelog fragments after zarr-developers#4597

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): keep same-named definitions out of nested draws

The struct and shard strategies removed the default definition by
identity before drawing what they hold. A custom definition with the
same name stayed in the inner strategies, so it could claim the name
there and be drawn, and the default then refused the result with a
ValueError. Filter by name instead.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): draw long runs in rectilinear dimensions

A run held at most 4 chunks, so the `[size, count]` spelling was never
drawn for what it is for, and a long dimension was covered by a few
small chunks and one huge one. Draw counts sized to the dimension, and
always write a run too long to list as a pair. Reach tests now cover
each spelling of a dimension, not only that a pair is drawn at all.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): sample float fills, shard factors and struct fields evenly

A measured audit found strategies that drew valid metadata from little
of what they could. Hex float fills came from a small-biased integer, so
83% of float64 fills were subnormal and few were normal. Integer float
fills stopped at the limit of the narrowest type. Rectilinear edges
rarely shared a factor, so 70% of a shard's axes held inner chunks of
length 1. A struct field's type was drawn after its name, which made
the first data type about a fifth of all fields.

Draw hex fills from floats, infinities and NaN payloads as well as raw
bits, limit integers by width, draw edges with a common factor, and draw
a field's type first. Divisor search is now bounded, so a very long
shard no longer takes billions of steps. New tests measure shares at the
number of examples a test runs, which plain reach tests do not see.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): keep regular chunk lengths within a signed 64-bit size

Axes can be up to 2**63 - 1 long, but regular and bare rectilinear chunk
lengths reached twice that, which a reader indexing with int64 cannot
hold. Cap them. A rectilinear last edge needs no cap: the runs before it
cover at least one factor, so rounding up cannot pass the axis.

Correct two docstrings, and require a covering run to count more than one
chunk in its reach test, since the leftover edge passed it on its own.

Assisted-by: ClaudeCode:claude-opus-5-5

* fix(zarr-metadata): draw non-finite and hex scale_offset values

An offset and a scale are fill values of the chunk's data type, but the
strategy drew only finite floats, and never an integer spelling. It now
draws every spelling a fill value takes, and still never a scale of zero.

Assisted-by: ClaudeCode:claude-opus-5-5
…r-9bd090

Main renamed the scopes to *_CONTEXT and fields to declarations, and
added scope update call sites (ZARR_PYTHON_CONTEXT, fixed_length_utf32,
the vlen codecs). Conflicts take main's side, then rewrite each scope
update into union (when it splices a slot's definitions back in) or
copy(update=...), and restore this branch's copy/union docs under the
new names.

Assisted-by: ClaudeCode:claude-opus-5-5
…nd name copy in scope docstrings

Assisted-by: ClaudeCode:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zarr-metadata: Scope.update() replaces slots whole; adding a definition can silently drop the defaults

1 participant