Skip to content

Commit fe62cd3

Browse files
committed
Fix decoding of complex fill values
1 parent 7a59d84 commit fe62cd3

File tree

1 file changed

+11
-1
lines changed
  • src/zarr/core/metadata

1 file changed

+11
-1
lines changed

src/zarr/core/metadata/v3.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343

4444
DEFAULT_DTYPE = "float64"
4545

46+
# Keep in sync with _replace_special_floats
47+
SPECIAL_FLOATS_ENCODED = {
48+
"Infinity": np.inf,
49+
"-Infinity": -np.inf,
50+
"NaN": np.nan,
51+
}
52+
4653

4754
def parse_zarr_format(data: object) -> Literal[3]:
4855
if data == 3:
@@ -447,8 +454,11 @@ def parse_fill_value(
447454
if isinstance(fill_value, Sequence) and not isinstance(fill_value, str):
448455
if data_type in (DataType.complex64, DataType.complex128):
449456
if len(fill_value) == 2:
457+
decoded_fill_value = tuple(
458+
SPECIAL_FLOATS_ENCODED.get(value, value) for value in fill_value
459+
)
450460
# complex datatypes serialize to JSON arrays with two elements
451-
return np_dtype.type(complex(*fill_value))
461+
return np_dtype.type(complex(*decoded_fill_value))
452462
else:
453463
msg = (
454464
f"Got an invalid fill value for complex data type {data_type.value}."

0 commit comments

Comments
 (0)