Skip to content

Commit

Permalink
ENH: warning on silent truncation of indices
Browse files Browse the repository at this point in the history
  • Loading branch information
dwf committed Dec 13, 2012
1 parent 35dc14b commit 48a06cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions numpy/core/src/multiarray/iterators.c
Expand Up @@ -70,6 +70,11 @@ parse_index_entry(PyObject *op, npy_intp *step_size,
}
*n_steps = SINGLE_INDEX;
*step_size = 0;
if (!PyIndex_Check_Or_Unsupported(op))
{
DEPRECATE("non-integer scalar index. In a future numpy "
"release, this will raise an error.");
}
if (check_index) {
if (check_and_adjust_index(&i, max, axis) < 0) {
goto fail;
Expand Down
12 changes: 11 additions & 1 deletion numpy/core/src/multiarray/mapping.c
Expand Up @@ -1150,6 +1150,11 @@ _tuple_of_integers(PyObject *seq, npy_intp *vals, int maxvals)
if (error_converting(temp)) {
return -1;
}
if (!PyIndex_Check_Or_Unsupported(obj))
{
DEPRECATE("non-integer scalar index. In a future numpy "
"release, this will raise an error.");
}
vals[i] = temp;
}
return 0;
Expand Down Expand Up @@ -1384,7 +1389,12 @@ array_subscript_nice(PyArrayObject *self, PyObject *op)
return PyArray_Scalar(item, PyArray_DESCR(self), (PyObject *)self);
}
PyErr_Clear();

if ((PyNumber_Check(op) || PyArray_IsScalar(op, Number)) &&
!PyIndex_Check_Or_Unsupported(op))
{
DEPRECATE("non-integer scalar index. In a future numpy "
"release, this will raise an error.");
}
mp = (PyArrayObject *)array_subscript(self, op);
/*
* mp could be a scalar if op is not an Int, Scalar, Long or other Index
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/private/npy_pycompat.h
Expand Up @@ -19,6 +19,10 @@
#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_ */

0 comments on commit 48a06cf

Please sign in to comment.