forked from zarr-developers/zarr-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* begin removing attrs in favor of frozen dataclasses * remove runtime_configuration from corearraymetadata; rename CodecMetadata to NamedConfig; turn chunk encoding into stand-alone functions; put codecs on ArrayMetadata instead of just CodecMetadata; add runtime_configuration parameter to codec encode / decode methods; add parsers to codecs * add typing_extensions dependency * remove CodecMetadatas and data_types; move basic parsers to common * feat: base to_dict method that actually works * Making Codec classes self-contained * fixes * chunk_grids * chunk key encodings * dry-er parse_* * serialize to enums * ruff * organize imports * rm src/zarr/v3/codecs/common.py * cleanup error messages * better codec evolve * __init__ types * add validation to RuntimeConfiguration.__init__; create a validator for c / f order; add order to ArrayV2Metadata.__init__ * import Dict at runtime * fix parse_dimension_names * add tests; tweak parse_name function; adjust some exception messages * fix shapelike parser and tests; clean up imports * typing * improve typing * blacken test_common --------- Co-authored-by: Norman Rzepka <code@normanrz.com>
- Loading branch information
Showing
27 changed files
with
1,812 additions
and
1,243 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING, Sequence | ||
|
||
if TYPE_CHECKING: | ||
from typing import Dict | ||
from typing_extensions import Self | ||
|
||
from dataclasses import fields | ||
|
||
from zarr.v3.common import JSON | ||
|
||
|
||
class Metadata: | ||
def to_dict(self) -> JSON: | ||
""" | ||
Recursively serialize this model to a dictionary. | ||
This method inspects the fields of self and calls `x.to_dict()` for any fields that | ||
are instances of `Metadata`. Sequences of `Metadata` are similarly recursed into, and | ||
the output of that recursion is collected in a list. | ||
""" | ||
... | ||
out_dict = {} | ||
for field in fields(self): | ||
key = field.name | ||
value = getattr(self, key) | ||
if isinstance(value, Metadata): | ||
out_dict[field.name] = getattr(self, field.name).to_dict() | ||
elif isinstance(value, str): | ||
out_dict[key] = value | ||
elif isinstance(value, Sequence): | ||
out_dict[key] = [v.to_dict() if isinstance(v, Metadata) else v for v in value] | ||
else: | ||
out_dict[key] = value | ||
|
||
return out_dict | ||
|
||
@classmethod | ||
def from_dict(cls, data: Dict[str, JSON]) -> Self: | ||
""" | ||
Create an instance of the model from a dictionary | ||
""" | ||
... | ||
|
||
return cls(**data) |
Oops, something went wrong.