summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2013-04-12 14:35:39 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2013-04-12 15:18:53 +0200
commit9466880fc907ddf864aab47aff0642a4cb57aaf6 (patch)
tree60fe51220a77fa16a53f90607ae9c0b54c6b14d0
parent07ed3a2defe68738ec89daf88e0a0e2e697a9182 (diff)
downloadnumpy-9466880fc907ddf864aab47aff0642a4cb57aaf6.tar.gz
MAINT: Error type fixup and clearer error message
The first error types were changed to ValueError (or introduced) newly. Python seems to normally use IndexError or TypeError here, so changing back to IndexError. The second is just a clarification to say when the error actually occurs for the user.
-rw-r--r--numpy/core/src/multiarray/mapping.c10
-rw-r--r--numpy/core/tests/test_indexing.py4
2 files changed, 7 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index fb01f20e3..0b4022874 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -1063,7 +1063,7 @@ array_subscript_fromobject(PyArrayObject *self, PyObject *op)
npy_intp value = PyArray_PyIntAsIntp(op);
if (value == -1 && PyErr_Occurred()) {
/* fail on error */
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_IndexError,
"cannot convert index to integer");
return NULL;
}
@@ -1387,7 +1387,7 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op)
npy_intp value = PyArray_PyIntAsIntp(ind);
if (value == -1 && PyErr_Occurred()) {
/* fail on error */
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_IndexError,
"cannot convert index to integer");
return -1;
}
@@ -1586,9 +1586,9 @@ _nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)
nd = PyArray_NDIM(ba);
if (nd == 0) {
- PyErr_SetString(PyExc_ValueError,
- "cannot construct index objects "
- "for zero-dimensional array");
+ PyErr_SetString(PyExc_IndexError,
+ "only scalars can be indexed by 0-dimensional "
+ "boolean arrays");
goto fail;
}
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 76a298059..7b7db02d0 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -70,8 +70,8 @@ class TestIndexing(TestCase):
# Index out of bounds produces IndexError
assert_raises(IndexError, a.__getitem__, 1<<30)
- # Index overflow produces ValueError
- assert_raises(ValueError, a.__getitem__, 1<<64)
+ # Index overflow produces IndexError
+ assert_raises(IndexError, a.__getitem__, 1<<64)
def test_single_bool_index(self):
# Single boolean index