diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2018-02-06 14:25:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-06 14:25:00 -0700 |
| commit | d328fdcbc0149fe3f960a5d9b66579af9f0f3948 (patch) | |
| tree | 5bc5fc20c2a2c370a235e6edb5c15ef7bec55a34 /numpy/core/src | |
| parent | c83653bfa894fa0eba20903c5a79df7ef444e859 (diff) | |
| parent | a2592e092a076bb0c87f5588dbffee4a6844dc08 (diff) | |
| download | numpy-d328fdcbc0149fe3f960a5d9b66579af9f0f3948.tar.gz | |
Merge pull request #10529 from eric-wieser/fix-pep3118-error
BUG: Provide a better error message for out-of-order fields
Diffstat (limited to 'numpy/core/src')
| -rw-r--r-- | numpy/core/src/multiarray/buffer.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index e76d406de..f892cf6cd 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -12,6 +12,7 @@ #include "npy_pycompat.h" #include "buffer.h" +#include "common.h" #include "numpyos.h" #include "arrayobject.h" @@ -243,14 +244,19 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str, child = (PyArray_Descr*)PyTuple_GetItem(item, 0); offset_obj = PyTuple_GetItem(item, 1); - new_offset = base_offset + PyInt_AsLong(offset_obj); + new_offset = PyInt_AsLong(offset_obj); + if (error_converting(new_offset)) { + return -1; + } + new_offset += base_offset; /* Insert padding manually */ if (*offset > new_offset) { - PyErr_SetString(PyExc_RuntimeError, - "This should never happen: Invalid offset in " - "buffer format string generation. Please " - "report a bug to the Numpy developers."); + PyErr_SetString( + PyExc_ValueError, + "dtypes with overlapping or out-of-order fields are not " + "representable as buffers. Consider reordering the fields." + ); return -1; } while (*offset < new_offset) { |
