diff options
-rw-r--r-- | numpy/core/src/multiarray/iterators.c | 53 | ||||
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 51 | ||||
-rw-r--r-- | numpy/core/src/private/npy_pycompat.h | 12 |
3 files changed, 8 insertions, 108 deletions
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c index abaff6c98..4584d0c60 100644 --- a/numpy/core/src/multiarray/iterators.c +++ b/numpy/core/src/multiarray/iterators.c @@ -70,12 +70,6 @@ parse_index_entry(PyObject *op, npy_intp *step_size, } *n_steps = SINGLE_INDEX; *step_size = 0; - if (!PyIndex_Check_Or_Unsupported(op)) { - if (DEPRECATE("non-integer scalar index. In a future numpy " - "release, this will raise an error.") < 0) { - goto fail; - } - } if (check_index) { if (check_and_adjust_index(&i, max, axis) < 0) { goto fail; @@ -204,26 +198,8 @@ parse_index(PyArrayObject *self, PyObject *op, static int slice_coerce_index(PyObject *o, npy_intp *v) { - /* - * PyNumber_Index was introduced in Python 2.5 because of NumPy. - * http://www.python.org/dev/peps/pep-0357/ - * Let's use it for indexing! - * - * Unfortunately, SciPy and possibly other code seems to rely - * on the lenient coercion. :( - */ -#if 0 /*PY_VERSION_HEX >= 0x02050000*/ - PyObject *ind = PyNumber_Index(o); - if (ind != NULL) { - *v = PyArray_PyIntAsIntp(ind); - Py_DECREF(ind); - } - else { - *v = -1; - } -#else *v = PyArray_PyIntAsIntp(o); -#endif + if ((*v) == -1 && PyErr_Occurred()) { PyErr_Clear(); return 0; @@ -231,24 +207,6 @@ slice_coerce_index(PyObject *o, npy_intp *v) return 1; } -/* - * Issue a DeprecationWarning for slice parameters that do not pass a - * PyIndex_Check, returning -1 if an error occurs. - * - * N.B. This function, like slice_GetIndices, will be obsolete once - * non-integer slice parameters becomes an error rather than a warning. - */ -static NPY_INLINE int -_validate_slice_parameter(PyObject *o) -{ - if (!PyIndex_Check_Or_Unsupported(o)) { - if (DEPRECATE("non-integer slice parameter. In a future numpy " - "release, this will raise an error.") < 0) { - return -1; - } - } - return 0; -} /* * This is basically PySlice_GetIndicesEx, but with our coercion @@ -268,9 +226,6 @@ slice_GetIndices(PySliceObject *r, npy_intp length, *step = 1; } else { - if (_validate_slice_parameter(r->step) < 0) { - return -1; - } if (!slice_coerce_index(r->step, step)) { return -1; } @@ -286,9 +241,6 @@ slice_GetIndices(PySliceObject *r, npy_intp length, *start = *step < 0 ? length-1 : 0; } else { - if (_validate_slice_parameter(r->start) < 0) { - return -1; - } if (!slice_coerce_index(r->start, start)) { return -1; } @@ -307,9 +259,6 @@ slice_GetIndices(PySliceObject *r, npy_intp length, *stop = defstop; } else { - if (_validate_slice_parameter(r->stop) < 0) { - return -1; - } if (!slice_coerce_index(r->stop, stop)) { return -1; } diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 17089761d..21874f8a9 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -560,33 +560,17 @@ array_subscript_simple(PyArrayObject *self, PyObject *op, int check_index) PyArrayObject *ret; npy_intp value; - /* - * PyNumber_Index was introduced in Python 2.5 because of NumPy. - * http://www.python.org/dev/peps/pep-0357/ - * Let's use it for indexing! - * - * Unfortunately, SciPy and possibly other code seems to rely - * on the lenient coercion. :( - */ if (!(PyArray_Check(op) && (PyArray_SIZE((PyArrayObject*)op) > 1))) { -#if 0 /*PY_VERSION_HEX >= 0x02050000*/ - PyObject *ind = PyNumber_Index(op); - if (ind != NULL) { - value = PyArray_PyIntAsIntp(ind); - Py_DECREF(ind); - } - else { - value = -1; - } -#else value = PyArray_PyIntAsIntp(op); -#endif + if (value == -1 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_TypeError)) { /* Operand is not an integer type */ PyErr_Clear(); } else { + PyErr_SetString(PyExc_IndexError, + "cannot convert index to integer"); return NULL; } } @@ -940,7 +924,6 @@ _is_full_index(PyObject *ind, PyArrayObject *arr) * Returns 0 if tuple-object seq is not a tuple of integers. * If the return value is positive, vals will be filled with the elements * from the tuple. - * Returns -1 on error. */ static int _tuple_of_integers(PyObject *seq, npy_intp *vals, int maxvals) @@ -960,12 +943,6 @@ _tuple_of_integers(PyObject *seq, npy_intp *vals, int maxvals) PyErr_Clear(); return 0; } - if (!PyIndex_Check_Or_Unsupported(obj)) { - if (DEPRECATE("non-integer scalar index. In a future numpy " - "release, this will raise an error.") < 0) { - return -1; - } - } vals[i] = temp; } return 1; @@ -1070,11 +1047,8 @@ array_subscript_fromobject(PyArrayObject *self, PyObject *op) /* optimization for a tuple of integers */ if (PyArray_NDIM(self) > 1 && _is_full_index(op, self)) { int ret = _tuple_of_integers(op, vals, PyArray_NDIM(self)); - /* In case an exception occurred (e.g. in PyErr_WarnEx) */ - if (ret < 0) { - return NULL; - } - else if (ret > 0) { + + if (ret > 0) { int idim, ndim = PyArray_NDIM(self); npy_intp *shape = PyArray_DIMS(self); npy_intp *strides = PyArray_STRIDES(self); @@ -1090,14 +1064,6 @@ array_subscript_fromobject(PyArrayObject *self, PyObject *op) } } - if ((PyNumber_Check(op) || PyArray_IsScalar(op, Number)) && - !PyIndex_Check_Or_Unsupported(op)) { - if (DEPRECATE("non-integer scalar index. In a future numpy " - "release, this will raise an error.") < 0) { - return NULL; - } - } - /* Check for single field access */ if (PyString_Check(op) || PyUnicode_Check(op)) { PyObject *temp, *obj; @@ -1472,11 +1438,8 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op) /* Integer-tuple index */ if (_is_full_index(ind, self)) { int ret = _tuple_of_integers(ind, vals, PyArray_NDIM(self)); - /* In case an exception occurred (e.g. in PyErr_WarnEx) */ - if (ret < 0) { - return -1; - } - else if (ret > 0) { + + if (ret > 0) { int idim, ndim = PyArray_NDIM(self); npy_intp *shape = PyArray_DIMS(self); npy_intp *strides = PyArray_STRIDES(self); diff --git a/numpy/core/src/private/npy_pycompat.h b/numpy/core/src/private/npy_pycompat.h index 2c76d68f4..8f596e75a 100644 --- a/numpy/core/src/private/npy_pycompat.h +++ b/numpy/core/src/private/npy_pycompat.h @@ -13,16 +13,4 @@ #define Py_SIZE(o) (((PyVarObject*)(o))->ob_size) #endif -/* - * PyIndex_Check - */ -#if (PY_VERSION_HEX < 0x02050000) -#undef PyIndex_Check -#define PyIndex_Check(o) 0 -#undef PyIndex_Check_Or_Unsupported -#define PyIndex_Check_Or_Unsupported(o) 1 -#else -#define PyIndex_Check_Or_Unsupported(o) PyIndex_Check(o) -#endif - #endif /* _NPY_COMPAT_H_ */ |