Skip to content
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

Add more setitem property tests #2825

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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