Repository navigation
fix(zarr-metadata): compare the declarations a configuration holds whatever order it writes them in - #4641
Merged
d-v-b merged 2 commits intoNov 17, 2026
Conversation
…atever order it writes them in `declaration_key` paired each nested declaration's key with its location, in the order the configuration wrote them. So two `sharding_indexed` codecs that differed only in whether `codecs` or `index_codecs` came first had different keys, and were not equal, although the order of the members of a JSON object means nothing and the rest of a configuration is already compared as sorted JSON text. The array models that held them were not equal either. The nested keys are now sorted by location. An index of an array sorts by its number, so the items of an array, such as the codecs of a pipeline, are still compared in order. Assisted-by: ClaudeCode:claude-fable-5-2
Assisted-by: ClaudeCode:claude-fable-5-2
This was referenced Nov 16, 2026
Draft
Merged
d-v-b
marked this pull request as ready for review
November 17, 2026 16:01
d-v-b
added a commit
to d-v-b/zarr-python
that referenced
this pull request
Nov 17, 2026
…canonical-documents Main now carries the chunk-aware canonical hook (zarr-developers#4640) and the nested declaration order fix (zarr-developers#4641). The one conflict was in model/_array_v3.py, where this branch adds canonical_array_document_v3 next to codecs_for_chunks; both are kept. Assisted-by: ClaudeCode:claude-fable-5-2
d-v-b
added a commit
to d-v-b/zarr-python
that referenced
this pull request
Nov 17, 2026
…at are not the default A review found that the Hypothesis tests passed with a canonicalize that returned the model's own document, that no test noticed a model losing its scope, and that four behaviours had no case: a claimed extra field, a v2 fill value, a chunk grid and a storage transformer that are respelled. The parametrized cases are now read in scopes that are not the default ones. The generated documents are compared with the same document reordered at every depth and, for arrays, with each declaration in its own simplest spelling. The reordering helper reverses every object, which the fix in zarr-developers#4641 allows. Assisted-by: ClaudeCode:claude-fable-5-2
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.
This PR ensures that the order of elements in a configuration dict for a nested declaration does not matter for the identity of the outer declaration.
🤖 AI text below 🤖
Two declarations that hold other declarations, such as two
sharding_indexedcodecs, are now equal when they differ only in the order their configurations write their members in. The declarations a configuration holds were compared in the order it writes them, so a shard that writesindex_codecsbeforecodecswas not equal to one that writes them the other way round, and neither were the array models that hold them, although the order of the members of a JSON object means nothing. The items of an array, such as the codecs of a pipeline, are still compared in order.How it was found, and the change
The agent found this while testing canonical documents: a v3 array document and the same document with the members of every object reversed read as two unequal models when it held a shard. Attributes, extra fields, unclaimed configurations and a configuration's own members are compared as sorted JSON text, so their order never mattered. Only
_nested_keyindefinition/_definition.pykept written order, because it iterated thenestedmapping. It now sorts by location, with a sort key that never compares an object key with an array index.refinesalready compared nested declarations by location, so it is unchanged.hashfollows==, since both use the key.Tests and checks
tests/v3/test_definitions.py: three cases added to the table oftest_two_declarations_are_equal_when_they_read_the_same. A shard with its members reversed is equal (this case fails without the fix), a shard with its index codecs in another order is not, and a codec with no nested declarations and its members reversed is equal, as before.ruff0.17.3 andpyright.Stack bookkeeping
mainat 95ec04a (zarr-metadata 0.9.0). Independent of feat(zarr-metadata): compare each codec in its simplest spelling for the chunk it receives #4640.🤖 Generated with Claude Code