|
31 | 31 | from zarr.registry import get_codec_class |
32 | 32 | from zarr.strings import STRING_DTYPE |
33 | 33 |
|
| 34 | +DEFAULT_DTYPE = "float64" |
| 35 | + |
34 | 36 |
|
35 | 37 | def parse_zarr_format(data: object) -> Literal[3]: |
36 | 38 | if data == 3: |
@@ -184,14 +186,14 @@ def __init__( |
184 | 186 | chunk_grid_parsed = ChunkGrid.from_dict(chunk_grid) |
185 | 187 | chunk_key_encoding_parsed = ChunkKeyEncoding.from_dict(chunk_key_encoding) |
186 | 188 | dimension_names_parsed = parse_dimension_names(dimension_names) |
187 | | - fill_value_parsed = parse_fill_value(fill_value, dtype=data_type_parsed.to_numpy_dtype()) |
| 189 | + fill_value_parsed = parse_fill_value(fill_value, dtype=data_type_parsed.to_numpy()) |
188 | 190 | attributes_parsed = parse_attributes(attributes) |
189 | 191 | codecs_parsed_partial = parse_codecs(codecs) |
190 | 192 | storage_transformers_parsed = parse_storage_transformers(storage_transformers) |
191 | 193 |
|
192 | 194 | array_spec = ArraySpec( |
193 | 195 | shape=shape_parsed, |
194 | | - dtype=data_type_parsed.to_numpy_dtype(), |
| 196 | + dtype=data_type_parsed.to_numpy(), |
195 | 197 | fill_value=fill_value_parsed, |
196 | 198 | order="C", # TODO: order is not needed here. |
197 | 199 | prototype=default_buffer_prototype(), # TODO: prototype is not needed here. |
@@ -225,13 +227,13 @@ def _validate_metadata(self) -> None: |
225 | 227 | raise ValueError("`fill_value` is required.") |
226 | 228 | for codec in self.codecs: |
227 | 229 | codec.validate( |
228 | | - shape=self.shape, dtype=self.data_type.to_numpy_dtype(), chunk_grid=self.chunk_grid |
| 230 | + shape=self.shape, dtype=self.data_type.to_numpy(), chunk_grid=self.chunk_grid |
229 | 231 | ) |
230 | 232 |
|
231 | 233 | @property |
232 | 234 | def dtype(self) -> np.dtype[Any]: |
233 | 235 | """Interpret Zarr dtype as NumPy dtype""" |
234 | | - return self.data_type.to_numpy_dtype() |
| 236 | + return self.data_type.to_numpy() |
235 | 237 |
|
236 | 238 | @property |
237 | 239 | def ndim(self) -> int: |
@@ -494,14 +496,14 @@ def to_numpy_shortname(self) -> str: |
494 | 496 | } |
495 | 497 | return data_type_to_numpy[self] |
496 | 498 |
|
497 | | - def to_numpy_dtype(self) -> np.dtype[Any]: |
| 499 | + def to_numpy(self) -> np.dtype[Any]: |
498 | 500 | if self == DataType.string: |
499 | 501 | return STRING_DTYPE |
500 | 502 | else: |
501 | 503 | return np.dtype(self.to_numpy_shortname()) |
502 | 504 |
|
503 | 505 | @classmethod |
504 | | - def from_numpy_dtype(cls, dtype: np.dtype[Any]) -> DataType: |
| 506 | + def from_numpy(cls, dtype: np.dtype[Any]) -> DataType: |
505 | 507 | if np.issubdtype(np.str_, dtype): |
506 | 508 | return DataType.string |
507 | 509 | dtype_to_data_type = { |
@@ -540,7 +542,7 @@ def parse(cls, dtype: None | DataType | Any) -> DataType: |
540 | 542 | raise ValueError(f"Invalid V3 data_type: {dtype}") from e |
541 | 543 | # check that this is a valid v3 data_type |
542 | 544 | try: |
543 | | - data_type = DataType.from_numpy_dtype(dtype) |
| 545 | + data_type = DataType.from_numpy(dtype) |
544 | 546 | except KeyError as e: |
545 | 547 | raise ValueError(f"Invalid V3 data_type: {dtype}") from e |
546 | 548 | return data_type |
0 commit comments