Skip to content

feat(zarr): store the source array metadata document on read (provenance) - #2

Open
d-v-b wants to merge 1 commit into
claude/zarr-encoding-refactorfrom
claude/zarr-metadata-fragment
Open

feat(zarr): store the source array metadata document on read (provenance)#2
d-v-b wants to merge 1 commit into
claude/zarr-encoding-refactorfrom
claude/zarr-metadata-fragment

Conversation

@d-v-b

@d-v-b d-v-b commented Jul 4, 2026

Copy link
Copy Markdown
Owner

🤖 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() — on encoding["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 as preferred_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

  • Upstream: promote zarr-python's private zarr/metadata/migrate_v3.py::_convert_array_metadata to a public, bidirectional (v3→v2) converter with an explicit "raise when unconvertible" contract.
  • Then: a future xarray increment can consume zarr_array_metadata on 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 to create) and reproduces the data. Full pytest -k zarr green; mypy clean on zarr.py.

Stacked on claude/zarr-encoding-refactor.

[This is Claude Code on behalf of Davis Vann Bennett]

🤖 Generated with Claude Code

@d-v-b d-v-b changed the title feat(zarr): carry zarr array metadata in encoding as a spec fragment (v2⇄v3 round-trips) feat(zarr): store the source array metadata document on read (provenance) Jul 4, 2026
@d-v-b
d-v-b force-pushed the claude/zarr-encoding-refactor branch from d4a4923 to eab28a3 Compare July 30, 2026 09:03
@d-v-b
d-v-b force-pushed the claude/zarr-metadata-fragment branch 3 times, most recently from 7668a40 to 34e4e81 Compare July 30, 2026 09:26
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
d-v-b force-pushed the claude/zarr-metadata-fragment branch from 34e4e81 to 943f9b4 Compare July 30, 2026 10:03
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.

1 participant