summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorNathan Goldbaum <nathan.goldbaum@gmail.com>2023-03-30 10:39:21 -0600
committerNathan Goldbaum <nathan.goldbaum@gmail.com>2023-03-30 10:39:21 -0600
commita0d872778e9c3d78a877c04d14b333be57732d24 (patch)
tree720991bf7f9c5cf3694ea1b09a9f802077def415 /numpy/core/src
parent3e77f904a9cc82e03d20824425e30edcd8088484 (diff)
downloadnumpy-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.c15
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;
}
}