Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed May 16, 2024
1 parent 9c0d840 commit 26af182
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3157,3 +3157,47 @@ def test_issue_1279(tmpdir):

written_data = ds_reopened[:]
assert_array_equal(data, written_data)


def test_scalar_indexing():
# regression test for #1874
store = zarr.KVStore({})

store["a"] = zarr.create((3,), chunks=(1,), store=store)
store["a"][:] = [1, 2, 3]

assert store["a"][1] == np.array(2.0)
assert store["a"][(1,)] == np.array(2.0)

store["a"][0] = [-1]
assert store["a"][0] == np.array(-1)

store["a"][0] = -2
assert store["a"][0] == np.array(-2)

store["a"][0] = (-3,)
assert store["a"][0] == np.array(-3)


def test_object_array_indexing():
# regression test for #1874
from numcodecs import MsgPack

root = zarr.group()
arr = root.create_dataset(
name="my_dataset",
shape=0,
dtype=object,
object_codec=MsgPack(),
)
new_items = [
["A", 1],
["B", 2, "hello"],
]
arr_add = np.empty(len(new_items), dtype=object)
arr_add[:] = new_items
arr.append(arr_add)

elem = np.array(["C", 3], dtype="O")
arr[0] = elem
assert arr[0] == elem

0 comments on commit 26af182

Please sign in to comment.