|
85 | 85 |
|
86 | 86 | def parse_zarr_format(data: Any) -> ZarrFormat: |
87 | 87 | """Parse the zarr_format field from metadata.""" |
88 | | - if data in (2, 3): |
89 | | - return cast("ZarrFormat", data) |
90 | | - msg = f"Invalid zarr_format. Expected one of 2 or 3. Got {data}." |
91 | | - raise ValueError(msg) |
| 88 | + from zarr.core.json_parse import parse_json |
| 89 | + |
| 90 | + try: |
| 91 | + return cast("ZarrFormat", parse_json(data, Literal[2, 3])) |
| 92 | + except (ValueError, TypeError) as exc: |
| 93 | + msg = f"Invalid zarr_format. Expected one of 2 or 3. Got {data}." |
| 94 | + raise ValueError(msg) from exc |
92 | 95 |
|
93 | 96 |
|
94 | 97 | def parse_node_type(data: Any) -> NodeType: |
95 | 98 | """Parse the node_type field from metadata.""" |
96 | | - if data in ("array", "group"): |
97 | | - return cast("Literal['array', 'group']", data) |
98 | | - msg = f"Invalid value for 'node_type'. Expected 'array' or 'group'. Got '{data}'." |
99 | | - raise MetadataValidationError(msg) |
| 99 | + from zarr.core.json_parse import parse_json |
| 100 | + |
| 101 | + try: |
| 102 | + return cast("Literal['array', 'group']", parse_json(data, Literal["array", "group"])) |
| 103 | + except (ValueError, TypeError) as exc: |
| 104 | + msg = f"Invalid value for 'node_type'. Expected 'array' or 'group'. Got '{data}'." |
| 105 | + raise MetadataValidationError(msg) from exc |
100 | 106 |
|
101 | 107 |
|
102 | 108 | # todo: convert None to empty dict |
|
0 commit comments