Skip to content

Commit dd03ff0

Browse files
dcheriandstansby
andauthored
Silence hypothesis complex warning (#2157)
* Silence hypothesis complex warning Closes #2155 * Use `array_equal` instead * Fix test * Add nan fill value test * better test * add equal_nan kwarg * cleanup * Update tests/v3/test_array.py Co-authored-by: David Stansby <[email protected]> --------- Co-authored-by: David Stansby <[email protected]>
1 parent bc82d02 commit dd03ff0

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/zarr/core/buffer/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,12 @@ def __len__(self) -> int:
462462
def __repr__(self) -> str:
463463
return f"<NDBuffer shape={self.shape} dtype={self.dtype} {self._data!r}>"
464464

465-
def all_equal(self, other: Any) -> bool:
466-
return bool((self._data == other).all())
465+
def all_equal(self, other: Any, equal_nan: bool = True) -> bool:
466+
"""Compare to `other` using np.array_equal."""
467+
# use array_equal to obtain equal_nan=True functionality
468+
data, other = np.broadcast_arrays(self._data, other)
469+
result = np.array_equal(self._data, other, equal_nan=equal_nan)
470+
return result
467471

468472
def fill(self, value: Any) -> None:
469473
self._data.fill(value)

tests/v3/test_array.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str
138138
assert arr.fill_value.dtype == arr.dtype
139139

140140

141+
@pytest.mark.parametrize("store", ["memory"], indirect=True)
142+
async def test_array_v3_nan_fill_value(store: MemoryStore) -> None:
143+
shape = (10,)
144+
arr = Array.create(
145+
store=store,
146+
shape=shape,
147+
dtype=np.float64,
148+
zarr_format=3,
149+
chunk_shape=shape,
150+
fill_value=np.nan,
151+
)
152+
arr[:] = np.nan
153+
154+
assert np.isnan(arr.fill_value)
155+
assert arr.fill_value.dtype == arr.dtype
156+
# all fill value chunk is an empty chunk, and should not be written
157+
assert len([a async for a in store.list_prefix("/")]) == 0
158+
159+
141160
@pytest.mark.parametrize("store", ("local",), indirect=["store"])
142161
@pytest.mark.parametrize("zarr_format", (2, 3))
143162
async def test_serializable_async_array(

tests/v3/test_properties.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ def test_roundtrip(data: st.DataObject) -> None:
1818

1919

2020
@given(data=st.data())
21-
# The filter warning here is to silence an occasional warning in NDBuffer.all_equal
22-
# See https://github.com/zarr-developers/zarr-python/pull/2118#issuecomment-2310280899
23-
# Uncomment the next line to reproduce the original failure.
24-
# @reproduce_failure('6.111.2', b'AXicY2FgZGRAB/8/ndR2z7nkDZEDADWpBL4=')
25-
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
2621
def test_basic_indexing(data: st.DataObject) -> None:
2722
zarray = data.draw(arrays())
2823
nparray = zarray[:]
@@ -37,11 +32,6 @@ def test_basic_indexing(data: st.DataObject) -> None:
3732

3833

3934
@given(data=st.data())
40-
# The filter warning here is to silence an occasional warning in NDBuffer.all_equal
41-
# See https://github.com/zarr-developers/zarr-python/pull/2118#issuecomment-2310280899
42-
# Uncomment the next line to reproduce the original failure.
43-
# @reproduce_failure('6.111.2', b'AXicY2FgZGRAB/8/eLmF7qr/C5EDADZUBRM=')
44-
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
4535
def test_vindex(data: st.DataObject) -> None:
4636
zarray = data.draw(arrays())
4737
nparray = zarray[:]

0 commit comments

Comments
 (0)