Skip to content

Commit e009fa3

Browse files
committed
Add regression test
1 parent 9c0d840 commit e009fa3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

zarr/tests/test_core.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,3 +3157,47 @@ def test_issue_1279(tmpdir):
31573157

31583158
written_data = ds_reopened[:]
31593159
assert_array_equal(data, written_data)
3160+
3161+
3162+
def test_scalar_indexing():
3163+
# regression test for #1874
3164+
store = zarr.KVStore({})
3165+
3166+
store["a"] = zarr.create((3,), chunks=(1,), store=store)
3167+
store["a"][:] = [1, 2, 3]
3168+
3169+
assert store["a"][1] == np.array(2.0)
3170+
assert store["a"][(1,)] == np.array(2.0)
3171+
3172+
store["a"][0] = [-1]
3173+
assert store["a"][0] == np.array(-1)
3174+
3175+
store["a"][0] = -2
3176+
assert store["a"][0] == np.array(-2)
3177+
3178+
store["a"][0] = (-3,)
3179+
assert store["a"][0] == np.array(-3)
3180+
3181+
3182+
def test_object_array_indexing():
3183+
# regression test for #1874
3184+
from numcodecs import MsgPack
3185+
3186+
root = zarr.group()
3187+
arr = root.create_dataset(
3188+
name="my_dataset",
3189+
shape=0,
3190+
dtype=object,
3191+
object_codec=MsgPack(),
3192+
)
3193+
new_items = [
3194+
["A", 1],
3195+
["B", 2, "hello"],
3196+
]
3197+
arr_add = np.empty(len(new_items), dtype=object)
3198+
arr_add[:] = new_items
3199+
arr.append(arr_add)
3200+
3201+
elem = ["C", 3]
3202+
arr[0] = elem
3203+
assert arr[0] == elem

0 commit comments

Comments
 (0)