diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2012-06-14 19:02:23 +0100 |
---|---|---|
committer | Nathaniel J. Smith <njs@pobox.com> | 2012-06-15 11:44:16 +0100 |
commit | 004082c59c102e2f458a595db8adecd21c18793f (patch) | |
tree | 288e6c140f300512a3994f5e51e3d9ffd35b20f3 | |
parent | a83e212d40ea4ccb49ab75a60fd5d7afa9307c2a (diff) | |
download | numpy-004082c59c102e2f458a595db8adecd21c18793f.tar.gz |
Tweak out-of-bounds exception message based on list feedback
-rw-r--r-- | numpy/core/src/multiarray/common.c | 31 | ||||
-rw-r--r-- | numpy/core/src/multiarray/common.h | 3 |
2 files changed, 10 insertions, 24 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c index a704fd1ad..4be3afb4d 100644 --- a/numpy/core/src/multiarray/common.c +++ b/numpy/core/src/multiarray/common.c @@ -513,30 +513,15 @@ check_and_adjust_index(npy_intp *index, npy_intp max_item, int axis) if ((*index < -max_item) || (*index >= max_item)) { /* Try to be as clear as possible about what went wrong. */ if (axis >= 0) { - if (max_item > 0) { - PyErr_Format(PyExc_IndexError, - "index %"NPY_INTP_FMT" is out of bounds for axis %d: " - "[%"NPY_INTP_FMT",%"NPY_INTP_FMT")", - *index, axis, - -max_item, max_item); - } else { - PyErr_Format(PyExc_IndexError, - "index %"NPY_INTP_FMT" is out of bounds for 0-d axis %d", - *index, axis); - } + PyErr_Format(PyExc_IndexError, + "index %"NPY_INTP_FMT" is out of bounds " + "for axis %d with size %"NPY_INTP_FMT, + *index, axis, max_item); } else { - if (max_item > 0) { - PyErr_Format(PyExc_IndexError, - "index %"NPY_INTP_FMT" is out of bounds: " - "[%"NPY_INTP_FMT",%"NPY_INTP_FMT")", - *index, - -max_item, max_item); - } else { - /* I don't believe there are currently any cases where this occurs. */ - PyErr_Format(PyExc_IndexError, - "index %"NPY_INTP_FMT" is out of bounds for 0-d axis", - *index); - } + PyErr_Format(PyExc_IndexError, + "index %"NPY_INTP_FMT" is out of bounds " + "for size %"NPY_INTP_FMT, + *index, max_item); } return -1; } diff --git a/numpy/core/src/multiarray/common.h b/numpy/core/src/multiarray/common.h index 085a91d01..a682a4a9d 100644 --- a/numpy/core/src/multiarray/common.h +++ b/numpy/core/src/multiarray/common.h @@ -45,7 +45,8 @@ _array_typedescr_fromstr(char *str); * Returns -1 and sets an exception if *index is an invalid index for * an array of size max_item, otherwise adjusts it in place to be * 0 <= *index < max_item, and returns 0. - * If axis >= 0, it will be reported as part of the exception. + * 'axis' should be the array axis that is being indexed over, if known. If + * unknown, use -1. */ NPY_NO_EXPORT int check_and_adjust_index(npy_intp *index, npy_intp max_item, int axis); |