From 68563e997aab1208c71efec5698c24214d840cda Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 22 Mar 2020 20:09:54 +0000 Subject: DEP: Make np.delete on out-of-bounds indices an error Note that this only affects lists of indices. ```python >>> a = np.arange(3) ```` Before: ```python >>> np.delete(a, 100) IndexError >>> np.delete(a, [100]) DeprecationWarning array([0, 1, 2]) >>> np.delete(a, -1) array([0, 1]) >>> np.delete(a, [-1]) FutureWarning array([0, 1, 2]) ``` After: ```python >>> np.delete(a, 100) IndexError >>> np.delete(a, [100]) IndexError >>> np.delete(a, -1) array([0, 1]) >>> np.delete(a, [-1]) array([0, 1]) ``` --- numpy/lib/tests/test_function_base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 860cf452b..b29e75471 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -807,7 +807,6 @@ class TestDelete: # NOTE: The cast should be removed after warning phase for bools if not isinstance(indices, (slice, int, long, np.integer)): indices = np.asarray(indices, dtype=np.intp) - indices = indices[(indices >= 0) & (indices < 5)] assert_array_equal(setxor1d(a_del, self.a[indices, ]), self.a, err_msg=msg) xor = setxor1d(nd_a_del[0,:, 0], self.nd_a[0, indices, 0]) @@ -825,10 +824,10 @@ class TestDelete: def test_fancy(self): # Deprecation/FutureWarning tests should be kept after change. self._check_inverse_of_slicing(np.array([[0, 1], [2, 1]])) - with warnings.catch_warnings(): - warnings.filterwarnings('error', category=DeprecationWarning) - assert_raises(DeprecationWarning, delete, self.a, [100]) - assert_raises(DeprecationWarning, delete, self.a, [-100]) + with pytest.raises(IndexError): + delete(self.a, [100]) + with pytest.raises(IndexError): + delete(self.a, [-100]) with warnings.catch_warnings(record=True) as w: warnings.filterwarnings('always', category=FutureWarning) self._check_inverse_of_slicing([0, -1, 2, 2]) -- cgit v1.2.1