-
-
Notifications
You must be signed in to change notification settings - Fork 378
Open
Description
Our Metadata base class defines to_dict and from_dict methods that are annotated as returning / taking dict[str, JSON]. This is problematic for two reasons:
- Codecs and data types can appear in Zarr V3 metadata as strings. So
from_dictneeds to accept strings, which makes the name of the method confusing. - Zarr metadata is structured, but
dict[str, JSON]cannot capture that structure. Typeddicts are a natural fit for modelling the exact structure of Zarr metadata documents, but typeddicts are not assignable todict[str, JSON], but ratherMapping[str, object]. So thedict[str, JSON]type is a blocker for using typeddicts withto_dict/from_dict(or whatever we call this method).
To get around these problems, I recommend:
- defining new methods
to_json,from_json. These methods take / return a type assignable toJSON = str | None | int | float | tuple[JSON, ...] | Mapping[str, object]. I think that's the best JSON type we can do until the assignment rules for typeddicts change. - deprecating
to_dictandfrom_dict, and replacing their usage withto_jsonandfrom_json.
I already did this with the data types, and it's worked fine. One complication for the data types is that we have 2 JSON serializations to handle: v2 and v3 JSON flavors. I addressed that with a zarr_format kwarg the dtype to_json / from_json methods. But for something like a codec, we can actually inspect the type of the input to check if it's a v2 or v3 codec, so we don't need the zarr_format kwarg.
Metadata
Metadata
Assignees
Labels
No labels