feat(zarr): store the source array metadata document on read (provenance) - #11483
Open
d-v-b wants to merge 2 commits into
Open
feat(zarr): store the source array metadata document on read (provenance)#11483d-v-b wants to merge 2 commits into
d-v-b wants to merge 2 commits into
Conversation
… path Define the encoding keys the Zarr backend accepts as module-level constants (ZARR_V2_ENCODING_KEYS, ZARR_V3_ENCODING_KEYS, ZARR_READ_ONLY_ENCODING_KEYS) and extract a pure _validate_zarr_variable_encoding helper from extract_zarr_variable_encoding. _create_new_array now assembles zarr create() arguments in its own dict instead of mutating the variable's encoding, takes the dimension names explicitly, and records them in one place for both zarr formats (native dimension_names metadata for format 3, the hidden _ARRAY_DIMENSIONS attribute for format 2). Remove unreachable "order" handling from array creation, and correct the formatting of the conflicting-write_empty_chunks error message. Behavior is otherwise unchanged; tests are split one case per function and new tests pin the constants and the conflict error. Assisted-by: ClaudeCode:claude-fable-5 Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Author
|
if this is merged, I would recommend considering a deprecation path for the current top-level encoding keys like If such a deprecation path isn't an option, then I recommend at a minimum deriving the values for these keys from the metadata document. Either way, the end goal is to use the metadata document as the source of truth for the structure of the zarr array, not the zarr array object. |
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.
Description
This PR adds a new
zarr_array_metadatakey to theencodingdict when reading a Zarr array.zarr_array_metadatais a dict representation of a zarr v2 or zarr v3 array metadata document. including this document in theencodingdict means xarray gains a simple, complete representation of input zarr data that's much more robust than vaguechunksandshardskeys.supporting this change are a few additions:
this PR is stacked on top of #11479. the end goal is closing out #11431, by getting xarray to use the stored array metadata for serializaing zarr data instead of keys like
shardsandchunks.Checklist
AI Disclosure