-
-
Notifications
You must be signed in to change notification settings - Fork 366
Fix JSON encoding of complex fill values #2432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
7a59d84
fe62cd3
d5352f6
7e2b28b
a0fb41f
3e5037f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import json | ||
| import math | ||
| import pickle | ||
| from itertools import accumulate | ||
| from typing import Any, Literal | ||
|
|
@@ -9,6 +11,7 @@ | |
| from zarr import Array, AsyncArray, Group | ||
| from zarr.codecs import BytesCodec, VLenBytesCodec | ||
| from zarr.core.array import chunks_initialized | ||
| from zarr.core.buffer import default_buffer_prototype | ||
| from zarr.core.buffer.cpu import NDBuffer | ||
| from zarr.core.common import JSON, MemoryOrder, ZarrFormat | ||
| from zarr.core.group import AsyncGroup | ||
|
|
@@ -624,3 +627,23 @@ def test_array_create_order( | |
| assert vals.flags.f_contiguous | ||
| else: | ||
| raise AssertionError | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("fill_value", "expected"), | ||
| [ | ||
| (np.nan * 1j, ["NaN", "NaN"]), | ||
| (np.nan, ["NaN", 0.0]), | ||
| (np.inf, ["Infinity", 0.0]), | ||
| (np.inf * 1j, ["NaN", "Infinity"]), | ||
| (-np.inf, ["-Infinity", 0.0]), | ||
| (math.inf, ["Infinity", 0.0]), | ||
| ], | ||
| ) | ||
| async def test_special_complex_fill_values_roundtrip(fill_value: Any, expected: list[Any]) -> None: | ||
| store = MemoryStore({}, mode="w") | ||
| Array.create(store=store, shape=(1,), dtype=np.complex64, fill_value=fill_value) | ||
| content = await store.get("zarr.json", prototype=default_buffer_prototype()) | ||
| assert content is not None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't we get an error later in the test if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is for mypy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that |
||
| actual = json.loads(content.to_bytes()) | ||
| assert actual["fill_value"] == expected | ||
Uh oh!
There was an error while loading. Please reload this page.