Repository navigation
fix(zarr-metadata): simplify a codec for its chunk in its canonical spelling, and check the result - #4647
Merged
d-v-b merged 9 commits intoDec 4, 2026
Conversation
…s canonical gives chunk_canonical received the configuration as written, and canonical ran afterwards. A codec whose canonical output its chunk_canonical reduces further then had two keys for one meaning: array models that differed only in such spellings were unequal, and the simplest spelling was not a fixed point. _for_chunk now hands chunk_canonical the configuration as canonical spells it, and checks that chunk_canonical has nothing left to simplify in its own result. A definition that leaves chunk_canonical at its default is skipped without calling either. Assisted-by: ClaudeCode:claude-fable-5-2
Assisted-by: ClaudeCode:claude-fable-5-2
… document it becomes A review of zarr-developers#4640 found gaps in how _for_chunk checks the result of chunk_canonical: - a result that added a nested declaration passed, and the respelled codec then held a declaration its nested mapping did not; - a result that was not JSON raised an error that did not name the definition; - an array written as a list was reported as a changed nested declaration; - a problem inside a nested declaration, which is the document's, was held against the result. The result is now refined as any JSON is, its declaration locations are compared with the codec's, and problems under a nested location are left out. respelled refuses a location that holds no nested declaration with the TypeError its docstring promises. Assisted-by: ClaudeCode:claude-fable-5-2
Assisted-by: ClaudeCode:claude-fable-5-2
This was referenced Nov 18, 2026
Merged
Merged
|
📖 2 files modified Preview · build overview · zarr-metadata · built Dec. 4, 2026, 6:47 p.m. UTC |
d-v-b
added a commit
to d-v-b/zarr-python
that referenced
this pull request
Nov 18, 2026
… from one normal form Merges refactor/zarr-metadata-one-normal-form, which holds the branches of zarr-developers#4642 and zarr-developers#4647, and takes its tree: refines reads the other model's document in this model's scope, so codec_refines and read_as_claimed are no longer needed and are removed. The changelog fragment is rewritten for the new behaviour. Assisted-by: ClaudeCode:claude-fable-5-2
…written in codec_for_chunk `codec_for_chunk` filtered out problems located inside a nested declaration, but `read_configuration` stops before running the rules when a nested declaration is malformed, so a `chunk_canonical` result that broke the codec's own rules could pass. A codec that holds a refused declaration now has no simpler spelling, as with any other problem, and its `chunk_canonical` is not asked. Correct the docs on what `codec_for_chunk` returns and on the simplest-spelling check, and test the early return for a codec with the default `chunk_canonical`. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dec that holds a refused declaration Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l fragment `chunk_canonical` arrived in zarr-developers#4640, which is not released yet, so the fragment describes the behavior instead of how it changed. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eeps only its own members `codec_for_chunk` still simplifies each codec of a pipeline such a codec contains, so the fragment, the docstring and the docs say that the codec keeps its own members as written. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4647 +/- ##
=======================================
Coverage 95.06% 95.06%
=======================================
Files 96 96
Lines 14126 14126
=======================================
Hits 13429 13429
Misses 697 697 🚀 New features to boost your workflow:
|
d-v-b
marked this pull request as ready for review
December 4, 2026 21:34
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 🤖
A v3 codec's
chunk_canonicalreceives the configuration as the codec'scanonicalspells it, so two spellings thatcanonicalreduces to one are simplified for a chunk in the same way. Its result is checked more closely: one that it would simplify again, or that holds a declaration the codec did not hold, raisesValueError, and one that is not JSON raisesTypeErrornaming the definition. A result may write an array as a list.chunk_canonicalis not asked about a codec that holds a refused declaration at any depth, which keeps its own members as written.Why
Subagent reviews of #4640 and #4642 found these in
_for_chunk, the function that asks a codec'schunk_canonical, which merged with #4640.chunk_canonicalwas called on the configuration as written, andcanonicalran afterwards. A codec whosecanonicaloutput itschunk_canonicalreduces further then had two keys for one meaning. The reproduction is a codec whosecanonicallowercasesmodeand whosechunk_canonicaldrops amodeof"auto": written with"AUTO", its simplest spelling was{"mode": "auto"}, which is not a fixed point, and two arrays that differed only in the case ofmodewere unequal.nestedmapping did not.chunk_canonicalcould never be taken, so every array codec was copied and serialised at every nesting level each time a model was compared or hashed. The first hash of 80 nested shards with nothing to simplify took 23.5 ms onmain, against 0.56 ms before feat(zarr-metadata): compare each codec in its simplest spelling for the chunk it receives #4640, and takes 0.66 ms here.No built-in definition is affected by the first four:
bytesis the only one with achunk_canonical, and it has nocanonical.Design notes
_for_chunkaskscanonicalfirst and hands its result tochunk_canonical. Whenchunk_canonicalchanges nothing in that spelling, the codec stays as written, as before.chunk_canonicalchanges its own result, the result was not the simplest spelling, andValueErrornames the definition.TypeErrornaming the definition.nested, through a newdeclaration_locations(definition, configuration).chunk_canonicalis not asked, and the codec keeps its own members as written. Each codec of a pipeline it contains is still simplified for the chunk that one receives. An earlier version of this PR askedchunk_canonicalanyway and left out every problem at or under a nested location; butread_configurationstops before the codec's rules when a nested declaration is malformed, so a result that broke the codec's own rules passed.chunk_canonicalat its default returns before anything is copied.respelledrefuses a location that is not the location of a nested declaration with theTypeErrorits docstring promised. Before, it raisedIndexErrororKeyError, and accepted a negative index and the empty location.docs/models.mdsays that, for a codec with no problems,canonical_ofwrites the codeccodec_for_chunkreturns in the spelling an array model compares.Not changed: when a leaf codec is simplified inside many nested shards, each level is rebuilt, so that case is still quadratic in nesting depth. It takes 22 ms at 80 levels, and the reader allows at most 84.
Tests and checks
tests/v3/test_pipelines.py: four cases of the parametrized simplest-spelling test with a codecacme.packthat has both functions; one success test of a result that writes a list; one test that a codec holding a refused declaration, directly or inside a shard it holds, keeps its own members and itschunk_canonicalis not asked; one test that a codec with the defaultchunk_canonicalis returned without asking itscanonical; error tests for a result with something left to simplify, one that adds a nested declaration, and one that is not JSON; the problem test now also uses achunk_canonicalthat would simplify a codec its chunk rules refuse.tests/v3/test_definitions.py: direct tests ofrespelled(three declarations, among them a name that carries its configuration) and ofitem_at, and one error test ofrespelledover five bad locations.chunk_canonicaltest, which guard behaviour that already held.just test-versions),ruff0.17.3,pyright,mkdocs build --strictand the pre-commit hooks.Review record
Review on 2026-12-04. A fresh subagent reviewed the open zarr-metadata PRs, and the agent confirmed each finding by tracing it before acting on it. Each fix was then reviewed by fresh subagents given the diff; rounds 1 and 2 found nothing serious.
chunk_canonicalresult that breaks the codec's own rules pass when a nested declaration is malformeddocs/models.mdsaidcodec_for_chunkreturns the compared spelling, though it returns the codec as written when nothing changesArrayCodecDefinitiondocstring did not say that the simplest-spelling check asks about the result ascanonicalspells itchunk_canonicalchunk_canonicalis never asked about a codec holding a refused declaration; a test name and a summary line claimed too much_holds_refusedrepeats the walk in_simplest_holds_refused, andcanonical_declarationdoes that walk oncechunk_canonicalarrived in #4640, which is not releasedBookkeeping
canonicalize()to be idempotent with such a codec.refinesacross scopes, the other regression the reviews found in feat(zarr-metadata): compare each codec in its simplest spelling for the chunk it receives #4640.🤖 Generated with Claude Code