|
| 1 | +import json |
| 2 | +import math |
1 | 3 | import pickle |
2 | 4 | from itertools import accumulate |
3 | 5 | from typing import Any, Literal |
|
9 | 11 | from zarr import Array, AsyncArray, Group |
10 | 12 | from zarr.codecs import BytesCodec, VLenBytesCodec |
11 | 13 | from zarr.core.array import chunks_initialized |
| 14 | +from zarr.core.buffer import default_buffer_prototype |
12 | 15 | from zarr.core.buffer.cpu import NDBuffer |
13 | 16 | from zarr.core.common import JSON, MemoryOrder, ZarrFormat |
14 | 17 | from zarr.core.group import AsyncGroup |
@@ -436,3 +439,23 @@ def test_array_create_order( |
436 | 439 | assert vals.flags.f_contiguous |
437 | 440 | else: |
438 | 441 | raise AssertionError |
| 442 | + |
| 443 | + |
| 444 | +@pytest.mark.parametrize( |
| 445 | + ("fill_value", "expected"), |
| 446 | + [ |
| 447 | + (np.nan * 1j, ["NaN", "NaN"]), |
| 448 | + (np.nan, ["NaN", 0.0]), |
| 449 | + (np.inf, ["Infinity", 0.0]), |
| 450 | + (np.inf * 1j, ["NaN", "Infinity"]), |
| 451 | + (-np.inf, ["-Infinity", 0.0]), |
| 452 | + (math.inf, ["Infinity", 0.0]), |
| 453 | + ], |
| 454 | +) |
| 455 | +async def test_special_complex_fill_values_roundtrip(fill_value: Any, expected: list[Any]) -> None: |
| 456 | + store = MemoryStore({}, mode="w") |
| 457 | + Array.create(store=store, shape=(1,), dtype=np.complex64, fill_value=fill_value) |
| 458 | + content = await store.get("zarr.json", prototype=default_buffer_prototype()) |
| 459 | + assert content is not None |
| 460 | + actual = json.loads(content.to_bytes()) |
| 461 | + assert actual["fill_value"] == expected |
0 commit comments