Skip to content

Commit d238278

Browse files
author
Angus
committed
derive platform-dependent NaN expectation from fill bits; ruff format
1 parent 8a2714a commit d238278

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎tests/test_array.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,17 +1037,26 @@ def test_write_empty_chunks_negative_zero(
10371037
(np.nan * 1j, ["NaN", "NaN"]),
10381038
(np.nan, ["NaN", 0.0]),
10391039
(np.inf, ["Infinity", 0.0]),
1040-
(np.inf * 1j, ["NaN", "Infinity"]),
1040+
(np.inf * 1j, None),
10411041
(-np.inf, ["-Infinity", 0.0]),
10421042
(math.inf, ["Infinity", 0.0]),
10431043
],
10441044
)
1045-
async def test_special_complex_fill_values_roundtrip(fill_value: Any, expected: list[Any]) -> None:
1045+
async def test_special_complex_fill_values_roundtrip(
1046+
fill_value: Any, expected: list[Any] | None
1047+
) -> None:
10461048
store = MemoryStore()
10471049
zarr.create_array(store=store, shape=(1,), dtype=np.complex64, fill_value=fill_value)
10481050
content = await store.get("zarr.json", prototype=default_buffer_prototype())
10491051
assert content is not None
10501052
actual = json.loads(content.to_bytes())
1053+
if expected is None:
1054+
# inf * 1j computes 0 * inf for the real part, which produces a NaN
1055+
# whose sign bit is platform-dependent. Only the exact canonical bits
1056+
# serialize as "NaN"; any other NaN writes as hex.
1057+
real_bits = int(np.array([np.complex64(fill_value)]).view(np.uint32)[0])
1058+
canonical = int(np.asarray(np.nan, dtype=np.float32).view(np.uint32))
1059+
expected = ["NaN" if real_bits == canonical else f"0x{real_bits:08x}", "Infinity"]
10511060
assert actual["fill_value"] == expected
10521061

10531062

‎tests/test_dtype/test_npy/test_float.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ def test_string_float_from_json_scalar() -> None:
239239
(Float64(), "0xfff8000000000000"),
240240
],
241241
)
242-
def test_noncanonical_nan_serializes_as_hex(
243-
dtype: BaseFloat[Any, Any], hex_value: str
244-
) -> None:
242+
def test_noncanonical_nan_serializes_as_hex(dtype: BaseFloat[Any, Any], hex_value: str) -> None:
245243
"""Only the exact canonical NaN bit pattern writes back as ``"NaN"``;
246244
every other NaN, including the negative-sign form of the canonical
247245
payload, writes back as its hex bits. Regression test for

0 commit comments

Comments
 (0)