Skip to content

BUG: Fix empty Group nodes lacking a "consolidated_metadata" field#3967

Open
TomAugspurger wants to merge 2 commits into
zarr-developers:mainfrom
TomAugspurger:tom/consolidated-metadata-leaf-node-fix
Open

BUG: Fix empty Group nodes lacking a "consolidated_metadata" field#3967
TomAugspurger wants to merge 2 commits into
zarr-developers:mainfrom
TomAugspurger:tom/consolidated-metadata-leaf-node-fix

Conversation

@TomAugspurger
Copy link
Copy Markdown
Contributor

@TomAugspurger TomAugspurger commented May 12, 2026

All nodes opened via open_consolidated are expected to have a non-null .metadata.consolidated_metadata. #3954 showed an example, with a data file written by zarr-python 2.x, where that condition failed to hold.

This happened because of a slight difference between how zarr-python 3.x writes consolidated metadata and how zarr-python 2.x wrote it. For leaf Group nodes (a Group with no Group or Array children), zarr-python 3.x includes an "empty" consolidated_metadata field. In zarr-python 3.x, we include a consolidated_metadata: metadata: {} field to indicate that it's empty. zarr-python 2.x didn't include that.

The fix is to update how we load this type of data. We effectively normalize a node missing consolidated metadata to one that is known not to have consolidated metadata (which is consistent with the idea behind consolidated metadata: just do one metadata read up front).

Closes #3954

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)

All nodes opened via `open_consolidated` are expected to have a non-null `.metadata.consolidated_metadata`. zarr-developers#3954 showed an example, with a data file written by zarr-python 2.x, where that condition failed to hold.

This happened because of a slight difference between how zarr-python 3.x writes consolidated metadata and how zarr-python 2.x wrote it. For leaf `Group` nodes (a `Group` with no `Group` or `Array` children), zarr-python 3.x includes an "empty" `consolidated_metadata` field.  In zarr-python 3.x, we include a `consolidated_metadata: metadata: {}` field to indicate that it's empty. zarr-python 2.x *didn't* include that.

The fix is to update how we load this type of data. We effectively normalize a node missing consolidated metadata to one that is known not to have consolidated metadata (which is consistent with the idea behind consolidated metadata: just do one metadata read up front).
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 12, 2026
Comment thread src/zarr/core/group.py
Comment on lines +277 to +278
if isinstance(child, GroupMetadata) and child.consolidated_metadata is None:
child = replace(child, consolidated_metadata=ConsolidatedMetadata(metadata={}))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new bit. The rest is rewriting the dic comprehension to a for loop.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.28%. Comparing base (c79425e) to head (eee40b2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3967   +/-   ##
=======================================
  Coverage   93.27%   93.28%           
=======================================
  Files          87       87           
  Lines       11739    11745    +6     
=======================================
+ Hits        10950    10956    +6     
  Misses        789      789           
Files with missing lines Coverage Δ
src/zarr/core/group.py 94.98% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidated Metadata Not Passed Down

1 participant