diff options
author | 87 <hangenuit@gmail.com> | 2011-10-17 00:29:21 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2013-04-11 16:40:49 +0200 |
commit | eab77ae891eaf08301de0c69f5b68021cd1d3ac9 (patch) | |
tree | 4b9aa152014193a82e28afc0d35122bd5b7c7de1 | |
parent | 793595279432e3f4627bf713ca3554c8caa3419e (diff) | |
download | numpy-eab77ae891eaf08301de0c69f5b68021cd1d3ac9.tar.gz |
ENH: Change silent integer conversion failure into index error.
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 9f09f27ca..c514cfe14 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1053,10 +1053,11 @@ array_subscript_fromobject(PyArrayObject *self, PyObject *op) if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || PyLong_Check(op) || (PyIndex_Check(op) && !PySequence_Check(op))) { - npy_intp value; - value = PyArray_PyIntAsIntp(op); - if (PyErr_Occurred()) { - PyErr_Clear(); + npy_intp value = PyArray_PyIntAsIntp(op); + if (value == -1 && PyErr_Occurred()) { + /* fail on error */ + PyErr_SetString(PyExc_IndexError, "integer index out of bounds"); + return NULL; } else { return array_item(self, (Py_ssize_t) value); |