Skip to content

Commit 1960e94

Browse files
committed
Allow for RuntimeError as well in test_single_int_index
Also allows for `IndexError` in `test_index_no_floats`
1 parent c1de2f0 commit 1960e94

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

torch_np/tests/numpy_tests/core/test_indexing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_index_no_floats(self):
4040
assert_raises(IndexError, lambda: a[-1.4, 0, 0])
4141
assert_raises(IndexError, lambda: a[0, -1.4, 0])
4242
# Note torch validates index arguments "depth-first", so will prioritise
43-
# raising TypeError, e.g.
43+
# raising TypeError over IndexError, e.g.
4444
#
4545
# >>> a = np.array([[[5]]])
4646
# >>> a[0.0:, 0.0]
@@ -52,8 +52,8 @@ def test_index_no_floats(self):
5252
# TypeError: slice indices must be integers or None or have an
5353
# __index__ method
5454
#
55-
assert_raises(TypeError, lambda: a[0.0:, 0.0])
56-
assert_raises(TypeError, lambda: a[0.0:, 0.0,:])
55+
assert_raises((IndexError, TypeError), lambda: a[0.0:, 0.0])
56+
assert_raises((IndexError, TypeError), lambda: a[0.0:, 0.0,:])
5757

5858
def test_slicing_no_floats(self):
5959
a = np.array([[5]])
@@ -199,7 +199,8 @@ def test_single_int_index(self):
199199
# Index out of bounds produces IndexError
200200
assert_raises(IndexError, a.__getitem__, 1 << 30)
201201
# Index overflow produces IndexError
202-
assert_raises(IndexError, a.__getitem__, 1 << 64)
202+
# Note torch raises RuntimeError here
203+
assert_raises((IndexError, RuntimeError), a.__getitem__, 1 << 64)
203204

204205
def test_single_bool_index(self):
205206
# Single boolean index

0 commit comments

Comments
 (0)