diff options
author | Nathan Goldbaum <nathan.goldbaum@gmail.com> | 2023-03-30 10:39:21 -0600 |
---|---|---|
committer | Nathan Goldbaum <nathan.goldbaum@gmail.com> | 2023-03-30 10:39:21 -0600 |
commit | a0d872778e9c3d78a877c04d14b333be57732d24 (patch) | |
tree | 720991bf7f9c5cf3694ea1b09a9f802077def415 /numpy/core/src | |
parent | 3e77f904a9cc82e03d20824425e30edcd8088484 (diff) | |
download | numpy-a0d872778e9c3d78a877c04d14b333be57732d24.tar.gz |
MAINT: improve error when a dtype doesn't support the buffer interface
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 76652550a..0bee223eb 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -17,6 +17,7 @@ #include "numpyos.h" #include "arrayobject.h" #include "scalartypes.h" +#include "dtypemeta.h" /************************************************************************* **************** Implement Buffer Protocol **************************** @@ -417,9 +418,17 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str, break; } default: - PyErr_Format(PyExc_ValueError, - "cannot include dtype '%c' in a buffer", - descr->type); + PyArray_DTypeMeta *DType = NPY_DTYPE(descr); + if (NPY_DT_is_legacy(DType)) { + PyErr_Format(PyExc_ValueError, + "cannot include dtype '%c' in a buffer", + descr->kind); + } + else { + PyErr_Format(PyExc_ValueError, + "cannot include dtype '%s' in a buffer", + ((PyTypeObject*)DType)->tp_name); + } return -1; } } |