Skip to content

Commit 23422fc

Browse files
authored
Update dtype usage in zarr/meta.py (#700)
* Update dtype usage in zarr/meta.py Changes in numpy have led to failures on `mypy zarr/` across a large number of PRs. * Revert encode_dtype return annotation
1 parent b0b161b commit 23422fc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

zarr/meta.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from zarr.errors import MetadataError
77
from zarr.util import json_dumps, json_loads
88

9-
from typing import Union, Any, List, Mapping as MappingType
9+
from typing import cast, Union, Any, List, Mapping as MappingType
1010

1111
ZARR_FORMAT = 2
1212

@@ -75,7 +75,7 @@ def encode_array_metadata(meta: MappingType[str, Any]) -> bytes:
7575
return json_dumps(meta)
7676

7777

78-
def encode_dtype(d: np.dtype) -> str:
78+
def encode_dtype(d: np.dtype):
7979
if d.fields is None:
8080
return d.str
8181
else:
@@ -180,8 +180,9 @@ def encode_fill_value(v: Any, dtype: np.dtype) -> Any:
180180
elif dtype.kind == 'b':
181181
return bool(v)
182182
elif dtype.kind in 'c':
183-
v = (encode_fill_value(v.real, dtype.type().real.dtype),
184-
encode_fill_value(v.imag, dtype.type().imag.dtype))
183+
c = cast(np.complex128, np.dtype(complex).type())
184+
v = (encode_fill_value(v.real, c.real.dtype),
185+
encode_fill_value(v.imag, c.imag.dtype))
185186
return v
186187
elif dtype.kind in 'SV':
187188
v = str(base64.standard_b64encode(v), 'ascii')

0 commit comments

Comments
 (0)