From e6f79af0b6011ab1ef9bac448609f86c671349b3 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 13 Feb 2025 08:58:11 -0700 Subject: [PATCH 1/3] Add more setitem property tests --- tests/test_properties.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/test_properties.py b/tests/test_properties.py index bf98f9d162..0bb802032d 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1,4 +1,3 @@ -import numpy as np import pytest from numpy.testing import assert_array_equal @@ -8,7 +7,7 @@ import hypothesis.extra.numpy as npst import hypothesis.strategies as st -from hypothesis import given +from hypothesis import assume, given from zarr.abc.store import Store from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata @@ -38,7 +37,7 @@ def test_basic_indexing(data: st.DataObject) -> None: actual = zarray[indexer] assert_array_equal(nparray[indexer], actual) - new_data = np.ones_like(actual) + new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) zarray[indexer] = new_data nparray[indexer] = new_data assert_array_equal(nparray, zarray[:]) @@ -54,6 +53,11 @@ def test_oindex(data: st.DataObject) -> None: actual = zarray.oindex[zindexer] assert_array_equal(nparray[npindexer], actual) + new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) + nparray[npindexer] = new_data + zarray.oindex[zindexer] = new_data + assert_array_equal(nparray, zarray[:]) + @given(data=st.data()) def test_vindex(data: st.DataObject) -> None: @@ -69,6 +73,15 @@ def test_vindex(data: st.DataObject) -> None: actual = zarray.vindex[indexer] assert_array_equal(nparray[indexer], actual) + # FIXME! + # when the indexer is such that a value gets overwritten multiple times, + # I think the output depends on chunking. Honestly I don't know why the 1D indexer works. + assume(indexer[0].ndim == 1) + new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) + nparray[indexer] = new_data + zarray.vindex[indexer] = new_data + assert_array_equal(nparray, zarray[:]) + @given(store=stores, meta=array_metadata()) # type: ignore[misc] async def test_roundtrip_array_metadata( From 217038992e5b76d98d86548919e9534f40deebb3 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 13 Feb 2025 09:20:19 -0700 Subject: [PATCH 2/3] comment out vindex setitem --- tests/test_properties.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test_properties.py b/tests/test_properties.py index 0bb802032d..e51fca6b98 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -7,7 +7,7 @@ import hypothesis.extra.numpy as npst import hypothesis.strategies as st -from hypothesis import assume, given +from hypothesis import given from zarr.abc.store import Store from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata @@ -75,12 +75,11 @@ def test_vindex(data: st.DataObject) -> None: # FIXME! # when the indexer is such that a value gets overwritten multiple times, - # I think the output depends on chunking. Honestly I don't know why the 1D indexer works. - assume(indexer[0].ndim == 1) - new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) - nparray[indexer] = new_data - zarray.vindex[indexer] = new_data - assert_array_equal(nparray, zarray[:]) + # I think the output depends on chunking. + # new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) + # nparray[indexer] = new_data + # zarray.vindex[indexer] = new_data + # assert_array_equal(nparray, zarray[:]) @given(store=stores, meta=array_metadata()) # type: ignore[misc] From 7fd4b14217a5f26f1b5f9632893abfbc11123ed6 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Fri, 14 Feb 2025 10:55:53 -0700 Subject: [PATCH 3/3] xfail with shards --- tests/test_properties.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_properties.py b/tests/test_properties.py index e51fca6b98..9b834a5eb0 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -7,7 +7,7 @@ import hypothesis.extra.numpy as npst import hypothesis.strategies as st -from hypothesis import given +from hypothesis import assume, given from zarr.abc.store import Store from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata @@ -53,6 +53,7 @@ def test_oindex(data: st.DataObject) -> None: actual = zarray.oindex[zindexer] assert_array_equal(nparray[npindexer], actual) + assume(zarray.shards is None) # GH2834 new_data = data.draw(npst.arrays(shape=st.just(actual.shape), dtype=nparray.dtype)) nparray[npindexer] = new_data zarray.oindex[zindexer] = new_data