Skip to content

Commit 40bb5a5

Browse files
committed
respect v3 core types
1 parent 515fd6f commit 40bb5a5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

zarr/meta.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@
1212
ZARR_FORMAT = 2
1313
ZARR_FORMAT_v3 = "3"
1414

15+
_v3_core_type = {
16+
"bool",
17+
"i1",
18+
"<i2",
19+
"<i4",
20+
"<i8",
21+
">i2",
22+
">i4",
23+
">i8",
24+
"u1",
25+
"<u2",
26+
"<u4",
27+
"<u8",
28+
"<f2",
29+
"<f4",
30+
"<f8",
31+
">f2",
32+
">f4",
33+
">f8",
34+
}
35+
1536

1637
def parse_metadata(s):
1738

@@ -34,7 +55,7 @@ def decode_array_metadata_v3(s):
3455

3556
# check metadata format
3657
# extract array metadata fields
37-
dtype = decode_dtype(meta["data_type"])
58+
dtype = decode_dtype_v3(meta["data_type"])
3859
fill_value = decode_fill_value(meta["fill_value"], dtype)
3960
meta = dict(
4061
shape=tuple(meta["shape"]),
@@ -46,6 +67,7 @@ def decode_array_metadata_v3(s):
4667
)
4768
return meta
4869

70+
4971
def decode_array_metadata(s):
5072
meta = parse_metadata(s)
5173

@@ -92,6 +114,14 @@ def encode_array_metadata(meta):
92114
return json_dumps(meta)
93115

94116

117+
def encode_dtype_v3(d: np.dtype) -> str:
118+
s = encode_dtype(d)
119+
if s == "|b1":
120+
return "bool"
121+
assert s in _v3_core_type
122+
return s
123+
124+
95125
def encode_dtype(d):
96126
if d.fields is None:
97127
return d.str
@@ -112,9 +142,15 @@ def decode_dtype(d):
112142
return np.dtype(d)
113143

114144

145+
def decode_dtype_v3(d):
146+
assert d in _v3_core_type
147+
return np.dtype(d)
148+
149+
115150
def decode_group_metadata_v3(s):
116151
return json.loads(s)
117152

153+
118154
def decode_group_metadata(s):
119155
meta = parse_metadata(s)
120156

0 commit comments

Comments
 (0)