feat(zarr): store the source array metadata document on read (provenance) - #2
Open
d-v-b wants to merge 1 commit into
Open
feat(zarr): store the source array metadata document on read (provenance)#2d-v-b wants to merge 1 commit into
d-v-b wants to merge 1 commit into
Conversation
d-v-b
force-pushed
the
claude/zarr-encoding-refactor
branch
from
July 30, 2026 09:03
d4a4923 to
eab28a3
Compare
d-v-b
force-pushed
the
claude/zarr-metadata-fragment
branch
3 times, most recently
from
July 30, 2026 09:26
7668a40 to
34e4e81
Compare
When a variable is read from a Zarr store, keep the array's complete metadata document on encoding["zarr_array_metadata"] for provenance and introspection. The key is read-only: it is listed in ZARR_READ_ONLY_ENCODING_KEYS, dropped on write, and never forwarded to zarr's array-creation call. The document is emitted by private per-format helpers (_v2_array_metadata, _v3_array_metadata) that read the metadata keys individually and return locally-defined TypedDicts mirroring the key names of the zarr-metadata package's ZarrV2ArrayMetadataJSON / ZarrV3ArrayMetadataJSON, with deliberately wide value types. These helpers are the only places xarray touches zarr-python's metadata API, so future changes to zarr-python's array class shape are absorbed there and surface loudly. Assisted-by: ClaudeCode:claude-fable-5 Co-authored-by: Claude <noreply@anthropic.com>
d-v-b
force-pushed
the
claude/zarr-metadata-fragment
branch
from
July 30, 2026 10:03
34e4e81 to
943f9b4
Compare
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 🤖
Summary
When a variable is read from a Zarr store (under zarr-python 3), xarray now stores the array's complete metadata document —
zarr.Array.metadata.to_dict()— onencoding["zarr_array_metadata"], for provenance and introspection.It is a read-only encoding key: added to
ZARR_READ_ONLY_ENCODING_KEYS, so it is dropped on write and never forwarded to zarr's array-creation call (same treatment aspreferred_chunks/source). The write path is unchanged.This is deliberately a small, gradual first increment.
Why this scope
An earlier version of this branch made the fragment authoritative on write (driving array creation, converting v2⇄v3, folding codecs, stamping dtype/fill_value). Review — including several rounds of automated review — showed that faithful cross-format metadata conversion is a hard, spec-level problem with a large correctness surface, and it really belongs upstream in zarr-python rather than reimplemented in xarray. So we walked back to just storing the document without consuming it. v2⇄v3 conversion is explicitly out of scope here.
Follow-ups
zarr/metadata/migrate_v3.py::_convert_array_metadatato a public, bidirectional (v3→v2) converter with an explicit "raise when unconvertible" contract.zarr_array_metadataon write (built on that upstream converter) to enable v2⇄v3 round-trips.Testing
test_zarr_array_metadata_stored_on_read: opening a v3 store exposes the self-describing document on.encoding; rewriting succeeds (the read-only key is dropped, not passed tocreate) and reproduces the data. Fullpytest -k zarrgreen;mypyclean onzarr.py.Stacked on
claude/zarr-encoding-refactor.[This is Claude Code on behalf of Davis Vann Bennett]
🤖 Generated with Claude Code