Skip to content

fix(zarr-metadata): treat two spellings of one v2 fill value, cast_value rounding or μs unit as equal - #498

Draft
d-v-b wants to merge 5 commits into
claude/audit-array-members-v3-480ed5from
claude/elastic-kilby-c8b441
Draft

d-v-b wants to merge 5 commits into
claude/audit-array-members-v3-480ed5from
claude/elastic-kilby-c8b441

Conversation

@d-v-b

@d-v-b d-v-b commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Array models that describe the same array are now equal in three more cases. A v2 fill value is compared as the value NumPy stores for the dtype: for <f4, 0.1 equals 0.10000000149011612; for |S3, "YQ==" equals "YQAA", which only adds padding; for <U2, "abc" equals "ab"; and two base64 spellings of the same bytes are equal. A v3 cast_value codec with a rounding of nearest-even equals one without a rounding. A numpy.datetime64 or numpy.timedelta64 with a unit of μs equals one with a unit of us. canonical_of and canonical_fill_value write the one spelling in each case. Which documents are accepted has not changed.

Stacked on #493 (claude/audit-array-members-v3-480ed5, at e9f017a) and targets its branch. It stays a draft until #493 merges and main is merged into this branch.

Summary (agent)
  • 5f352722f v2 fill values: canonical spelling follows what NumPy stores, checked against zarr-python 2.18.7. Acceptance is unchanged. Only base64 checks, μs=us and S null padding are shared with v3 (_numpy.py); each definition cites its own spec.
  • c9368233c without_defaults / with_defaults (internal) replace eleven hand-written canonical functions; cast_value gains rounding="nearest-even".
  • dfb6ca0d6 v3 numpy time types canonicalize μs to us.
  • 83d7f4b33 docs: Equality section of docs/models.md.
  • 8e0714fd7 changelog fragment.

Deliberate v2/v3 differences: v2 floats are spelled as the exact float64 zarr-python 2 writes (v3 writes the shortest number); v2 <U cuts an over-long fill value as NumPy does (v3 fixed_length_utf32 refuses it).

Review record (agent)

Four rounds, fresh reviewers each; rounds 3 and 4 found nothing serious.

Round 1 (full diff, two reviewers):

  • <U0 fill values all canonicalized to "" (serious, reproduced): fixed in 5f352722f.
  • Property test did not test one-spelling-per-value: replaced by a test against a stored-bytes oracle, 5f352722f.
  • No model-level test for μs: added in dfb6ca0d6.
  • Citation line ranges off by one: fixed in 5f352722f.
  • Hash of a definition re-encoded JSON: text derived once, c9368233c.
  • No test that absent out_of_range differs from clamp: row added, c9368233c.
  • Rejected: checking declared defaults against the configuration TypedDict, exporting the helpers (left for a decision); cross-version pickles (pre-1.0).

Round 2 (full diff, two reviewers):

  • <U0 "kept as written" rested on a false NumPy claim (serious, reproduced): <U0 now read as one code point, as zarr-python 2 fills it, 5f352722f.
  • Test oracle docstring overclaimed agreement with zarr-python 2 for complex and huge integers: scoped, 5f352722f.
  • text field could disagree with defaults: derived in __post_init__, c9368233c.
  • Docstring and docs link corrections: c9368233c, 83d7f4b33.

Round 3 (fix diff): no serious finding.

  • Sorting declared defaults reordered v2 zstd/lzma canonical members away from numcodecs' order (regression from the round 2 fix): sort removed, equality follows declared order, c9368233c.
  • <U0 docstring scoped to allocated arrays and unstored chunks: 5f352722f.

Round 4 (fix diff): no serious finding.

  • No test pinned v2 codec member order: tests/v2/test_codecs.py now compares order, c9368233c.
  • Rejected: without_defaults equality is order-sensitive though its output is not (kept: one rule for both helpers).

Not changed, found in review: scale_offset absent offset/scale and cast_value empty scalar_map still compare unequal to their written defaults; v2 |S/|V/struct refuse over-long or short fill values that zarr-python 2 cuts or pads.

🤖 Generated with Claude Code

d-v-b and others added 5 commits December 4, 2026 19:30
Two v2 array models compared unequal when their fill values were the
same value written two ways. The canonical spelling of a v2 fill value
now names the value NumPy stores for the dtype, because the v2 spec
gives the dtype as a NumPy typestr:

- a number for a float dtype is the float of the dtype's width that it
  reads as, written as a float64, so `0.1` and `0.10000000149011612`
  are one `<f4` value;
- a `|S` value drops its trailing null bytes, and a `|S`, `|V` or
  struct value is encoded in base64 again, so `"QR=="` and `"QQ=="`
  are one value;
- a `<U<n>` value is cut to `n` code points and drops its trailing
  `U+0000` code points. A `<U0` value is cut to one code point, because
  NumPy allocates an array of `U0` as an array of `U1`.

For floats, `|S`, `|V` and structs this is also the spelling
zarr-python 2.18.7 writes back. Which fill values a v2 dtype accepts is
unchanged. The base64 checks and the `μs`/`us` unit, which both formats
take from base64 and NumPy, are defined once in `zarr_metadata._numpy`.
Each definition keeps its own rules and cites its own spec.

Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The `cast_value` spec says an absent `rounding` means `"nearest-even"`,
but a model that wrote it and one that left it out compared unequal.
`without_defaults` and `with_defaults` build a `canonical` from the
defaults of a configuration. They replace the hand-written functions of
the v3 `zstd` and `sharding_indexed` codecs, of the `default` and `v2`
chunk key encodings, and of the v2 `zlib`, `gzip`, `bz2`, `lzma`, `zstd`,
`lz4` and `shuffle` codecs: a v3 definition drops a member written with
its default, and a v2 codec writes each absent member, in the order
numcodecs writes them.

Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The `numpy.datetime64` and `numpy.timedelta64` specs say that `"us"` and
`"μs"` are equivalent, but two v3 array models that differed only in
that spelling compared unequal. The canonical configuration now writes
`us`, as NumPy does.

Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ue` rounding and `μs`

Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assisted-by: ClaudeCode:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant