Skip to content

Commit

Permalink
Add more setitem property tests (#2825)
Browse files Browse the repository at this point in the history
* Add more setitem property tests

* comment out vindex setitem

* xfail with shards
  • Loading branch information
dcherian authored Feb 14, 2025
1 parent f8bc315 commit 23abb5b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import pytest
from numpy.testing import assert_array_equal

Expand All @@ -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
Expand Down Expand Up @@ -57,7 +56,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[:])
Expand All @@ -73,6 +72,12 @@ 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
assert_array_equal(nparray, zarray[:])


@given(data=st.data())
def test_vindex(data: st.DataObject) -> None:
Expand All @@ -88,6 +93,14 @@ 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.
# 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(
Expand Down

0 comments on commit 23abb5b

Please sign in to comment.