Skip to content

fix: make consolidated metadata nesting independent of persisted key order - #4227

Open
d-v-b wants to merge 3 commits into
zarr-developers:mainfrom
d-v-b:claude/zarr-python-issue-4226-0b896e
Open

fix: make consolidated metadata nesting independent of persisted key order#4227
d-v-b wants to merge 3 commits into
zarr-developers:mainfrom
d-v-b:claude/zarr-python-issue-4226-0b896e

Conversation

@d-v-b

@d-v-b d-v-b commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

itertools.groupby strikes again, this time in our deserialization of consolidated metadata. see d-v-b#273 for the full AI writeup, but basically itertertools.groupby only groups locally, not globally, so it wasn't gathering all child keys from the flat list of consolidated metadata keys correctly. This PR fixes that behavior by using accumulating into a defaultdict instead of using groupby.

claude did the diagnosis and the fix. I wrote the complaints about groupby

closes #4226

note that the reproducer in #4226 is also affected by case-insensitive file system issues, which mask the underlying "parse consolidated metadata incorrectly" issue. See d-v-b#273 for the full AI-written explanation.

For reviewers

check that this is correct.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

d-v-b added 2 commits August 1, 2026 20:40
…order

`ConsolidatedMetadata._flat_to_nested` grouped the flat keys with
`itertools.groupby` over keys sorted by depth alone. `groupby` only groups
*consecutive* runs, so when a parent's children were not adjacent it emitted
several runs for the same parent and the surrounding dict comprehension kept
only the last one. Every child in the earlier runs was silently never
re-parented, and lingered as a bogus slash-containing key at the top level,
making it unreachable through the consolidated metadata.

The persisted key order is arbitrary, so nesting must not depend on it. Group
by parent with an accumulating mapping instead.

This is reachable from zarr-python itself: `to_dict` sorts keys by
`(depth, NFKC-casefold(key))`, so sibling subtrees whose names differ only by
case interleave and trigger exactly this pattern.

Fixes zarr-developers#4226

Assisted-by: ClaudeCode:claude-opus-5
Assisted-by: ClaudeCode:claude-opus-5
@d-v-b
d-v-b requested a review from ilan-gold August 1, 2026 18:51
@d-v-b
d-v-b marked this pull request as ready for review August 1, 2026 18:51
@d-v-b d-v-b changed the title Claude/zarr python issue 4226 0b896e fix: make consolidated metadata nesting independent of persisted key order Aug 1, 2026
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.

consolidated metadata does not capture differently-cased keys

2 participants