summaryrefslogtreecommitdiff
path: root/numpy/core/src/arraymethods.c
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src/arraymethods.c')
-rw-r--r--numpy/core/src/arraymethods.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c
index e2dbaa717..3572633ef 100644
--- a/numpy/core/src/arraymethods.c
+++ b/numpy/core/src/arraymethods.c
@@ -479,7 +479,9 @@ array_toscalar(PyArrayObject *self, PyObject *args) {
PyErr_SetString(PyExc_ValueError, "invalid integer");
return NULL;
}
- if (value >= PyArray_SIZE(self)) {
+ factor = PyArray_SIZE(self);
+ if (value < 0) value += factor;
+ if ((value >= factor) || (value < 0)) {
PyErr_SetString(PyExc_ValueError,
"index out of bounds");
return NULL;