summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2021-10-21 12:27:47 -0600
committerGitHub <noreply@github.com>2021-10-21 12:27:47 -0600
commit76f1edbe09f45e701544498aad2251215aa51c97 (patch)
tree4545b9b67c15bd617305a53f8244972eaa7ba476
parent1f0cd59aa10560632d635cf094d8cca5e590ed11 (diff)
parentbe11c06de7cf128c364c33dafbdecd2372f322e6 (diff)
downloadnumpy-76f1edbe09f45e701544498aad2251215aa51c97.tar.gz
Merge pull request #20150 from WarrenWeckesser/fix-insert-incorrect-error
BUG: lib: Fix error raised by insert.
-rw-r--r--numpy/lib/function_base.py5
-rw-r--r--numpy/lib/tests/test_function_base.py5
2 files changed, 7 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 84128e4f0..232a51cab 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -4753,9 +4753,8 @@ def insert(arr, obj, values, axis=None):
if indices.size == 1:
index = indices.item()
if index < -N or index > N:
- raise IndexError(
- "index %i is out of bounds for axis %i with "
- "size %i" % (obj, axis, N))
+ raise IndexError(f"index {obj} is out of bounds for axis {axis} "
+ f"with size {N}")
if (index < 0):
index += N
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 66110b479..c7dfe5673 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -553,6 +553,11 @@ class TestInsert:
with pytest.raises(IndexError):
np.insert([0, 1, 2], np.array([], dtype=float), [])
+ @pytest.mark.parametrize('idx', [4, -4])
+ def test_index_out_of_bounds(self, idx):
+ with pytest.raises(IndexError, match='out of bounds'):
+ np.insert([0, 1, 2], [idx], [3, 4])
+
class TestAmax: