Skip to content

fix(zarr-metadata): model stored metadata more closely#3962

Open
d-v-b wants to merge 5 commits intozarr-developers:mainfrom
d-v-b:update-zarr-metadata
Open

fix(zarr-metadata): model stored metadata more closely#3962
d-v-b wants to merge 5 commits intozarr-developers:mainfrom
d-v-b:update-zarr-metadata

Conversation

@d-v-b
Copy link
Copy Markdown
Contributor

@d-v-b d-v-b commented May 10, 2026

Zarr V2 uses a separate JSON document named .zattrs for the attributes of an array or group.
This package was inconsistent about how it modelled this fact. The array metadata document type modelled
array fields (shape, dtype, etc), which would be stored in .zarray, AND the attributes field,
which would be stored in .zattrs. Thus the array metadata model matched the representation
of an array that a program might use, rather than the stored layout. But the group metadata type didn't
follow this pattern -- it has no attributes field.

This PR addresses that inconsistency by adding an attributes field to GroupMetadataV2. That field is
not required. To model the stored representation of V2 data, this PR adds 3 new types: ZArrayMetadata,
ZGroupMetadata, and ZAttrsMetadata, that closely model the contents of the .zarray, .zgroup, and
.zattrs documents, respectively.

This change makes the V2 consolidated metadata type more accurate, as consolidated metadata for Zarr V2
is comprised of inlined metadata documents.

d-v-b and others added 4 commits May 10, 2026 10:36
Zarr V2 uses a separate JSON document named `.zattrs` for the attributes of an array or group.
This package was inconsistent about how it modelled this fact. The array metadata document type modelled
array fields (`shape`, `dtype`, etc), which would be stored in `.zarray`,  AND the `attributes` field,
which would be stored in `.zattrs`. Thus the array metadata model matched the representation
of an array that a program might use, rather than the stored layout. But the group metadata type didn't
follow this pattern -- it has no `attributes` field.

This PR addresses that inconsistency by adding an `attributes` field to `GroupMetadataV2`. That field is
not required. To model the stored representation of V2 data, this PR adds 3 new types: `ZArrayMetadata`,
`ZGroupMetadata`, and `ZAttrsMetadata`, that closely model the contents of the `.zarray`, `.zgroup`, and
`.zattrs` documents, respectively.

This change makes the V2 consolidated metadata type more accurate, as consolidated metadata for Zarr V2
is comprised of inlined metadata documents.
…Metadata at top level

The on-disk file types added in 8b7af90 were importable from the
v2 submodule but not from the package root. Add them to the top-level
__init__.py so consumers can import them as `zarr_metadata.ZArrayMetadata`
etc.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 10, 2026
@d-v-b d-v-b requested a review from ilan-gold May 10, 2026 19:03
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (84532ca) to head (4e50736).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3962   +/-   ##
=======================================
  Coverage   93.26%   93.26%           
=======================================
  Files          87       87           
  Lines       11721    11721           
=======================================
  Hits        10932    10932           
  Misses        789      789           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b
Copy link
Copy Markdown
Contributor Author

d-v-b commented May 10, 2026

cc @chuckwondo

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.

1 participant