Skip to content

Commit eb39593

Browse files
committed
Add tests for implicit fancy indexing, and getitem
1 parent 4b05000 commit eb39593

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

zarr/tests/test_indexing.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,43 @@ def test_fancy_indexing_fallback_on_get_setitem():
305305
np.testing.assert_array_equal(
306306
z[1, [1, 2, 3]], [1, 0, 0]
307307
)
308+
# test 1D fancy indexing
309+
z2 = zarr.zeros(5)
310+
z2[[1, 2, 3]] = 1
311+
np.testing.assert_array_equal(
312+
z2, [0, 1, 1, 1, 0]
313+
)
308314

309315

310316
def test_fancy_indexing_doesnt_mix_with_slicing():
311317
z = zarr.zeros((20, 20))
312318
with pytest.raises(IndexError):
313319
z[[1, 2, 3], :] = 2
320+
with pytest.raises(IndexError):
321+
np.testing.assert_array_equal(
322+
z[[1, 2, 3], :], 0
323+
)
324+
325+
def test_fancy_indexing_doesnt_mix_with_implicit_slicing():
326+
z2 = zarr.zeros((5, 5, 5))
327+
with pytest.raises(IndexError):
328+
z2[[1, 2, 3], [1, 2, 3]] = 2
329+
with pytest.raises(IndexError):
330+
np.testing.assert_array_equal(
331+
z2[[1, 2, 3], [1, 2, 3]], 0
332+
)
333+
with pytest.raises(IndexError):
334+
z2[[1, 2, 3]] = 2
335+
with pytest.raises(IndexError):
336+
np.testing.assert_array_equal(
337+
z2[[1, 2, 3]], 0
338+
)
339+
with pytest.raises(IndexError):
340+
z2[..., [1, 2, 3]] = 2
341+
with pytest.raises(IndexError):
342+
np.testing.assert_array_equal(
343+
z2[..., [1, 2, 3]], 0
344+
)
314345

315346

316347
def test_set_basic_selection_0d():

0 commit comments

Comments
 (0)