pydata / pydata/xarray

a proposal to simplify encoding for zarr data

Open
#11,431 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic-zarr
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What is your issue?

When used for zarr data, the .encoding dict is populated with keys derived from the signature of a high-level function (zarr.create_array). That function is abstract, and deliberately elides differences between zarr v2 and zarr v3 data, and obscures important properties of the an array, like the exact chunk grid metadata it uses.

Better than the signature of create_array is an array metadata document itself. The array metadata document is small and defined by the zarr specs, so it's independent of zarr-python changes. You could represent the array metadata as a dict, or as a dataclass, if that's more ergonomic (a dict is simpler in case there are extra fields in metadata).

I think this could work by adding a new zarr_array_metadata key to the encoding dict. The value is a dict that models either a zarr v2 or zarr v3 metadata document. Zarr python (and any other zarr implementation) can create an array from a plain metadata dict. Note: the metadata is a complete description of a stored array, but it doesn't include runtime configuration like write_empty_chunks, so you might need a separate zarr_array_config key for this, if you want to consolidate that kind of configuration info. In any case, the full metadata document is a much more durable representation of an array than what you are using today (a subset of the signature of create_array)

xarray would need a bit of machinery to ensure that the old encoding keys still work, that their value is consistent with the array metadata, and that their use is ultimately deprecated. And it's likely that we need to improve things on the zarr-metadata side, to make the static types better. But I think this is a much better direction than putting create_array kwargs in your encoding dict.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the zarr-metadata v2 and v3 array.py definitions linked in the issue, then trace xarray’s current encoding handling for zarr.create_array kwargs. Determine how zarr_array_metadata and runtime configuration should coexist with legacy encoding keys and how consistency should be tested. Done means supporting a durable v2/v3 metadata representation without breaking existing encoding behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.