diff options
author | Yilin LI <yilin.lasia@gmail.com> | 2020-03-26 20:57:46 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 13:57:46 +0200 |
commit | dfd4c9de8d849363e3d4cda7a0792ed0670165cf (patch) | |
tree | f8418e03c0df97db1f64acc8fa039bc44893786a /numpy/core/tests | |
parent | 68439794b84836f43ec389be0e702ff64ee76d44 (diff) | |
download | numpy-dfd4c9de8d849363e3d4cda7a0792ed0670165cf.tar.gz |
ENH: improved error message `IndexError: too many indices for array` (#15832)
* ENH: improved error message when the dimension of index is larger than the dimension of array, fixed issue #15321
Author: Yilin Li <yilin.lasia@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_indexerrors.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/core/tests/test_indexerrors.py b/numpy/core/tests/test_indexerrors.py index 9d2433fc5..a0e9a8c55 100644 --- a/numpy/core/tests/test_indexerrors.py +++ b/numpy/core/tests/test_indexerrors.py @@ -1,5 +1,8 @@ import numpy as np -from numpy.testing import assert_raises +from numpy.testing import ( + assert_raises, assert_raises_regex, + ) + class TestIndexErrors: '''Tests to exercise indexerrors not covered by other tests.''' @@ -110,6 +113,15 @@ class TestIndexErrors: assert_raises(IndexError, lambda: a[(1, [0, 1])]) assert_raises(IndexError, lambda: assign(a, (1, [0, 1]), 1)) + def test_mapping_error_message(self): + a = np.zeros((3, 5)) + index = (1, 2, 3, 4, 5) + assert_raises_regex( + IndexError, + "too many indices for array: " + "array is 2-dimensional, but 5 were indexed", + lambda: a[index]) + def test_methods(self): "cases from methods.c" |