diff options
author | Sebastian Berg <sebastianb@nvidia.com> | 2022-12-12 10:23:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 10:23:53 +0100 |
commit | a24ddad5d1d43ec9bea474abf8068ee6b8db01db (patch) | |
tree | b5d4e6e43846333a21c724f420efd0f1c8d8eecc | |
parent | 73bb6411612a10ae963569ade609495e02e475e1 (diff) | |
parent | 95cb62bce3591664df54205ffc7ee800330a3cbb (diff) | |
download | numpy-a24ddad5d1d43ec9bea474abf8068ee6b8db01db.tar.gz |
Merge pull request #22763 from ngoldbaum/legacy-dtype-check-unsized
MAINT: allow unsized NEP 42 user-defined dtypes
-rw-r--r-- | numpy/core/src/multiarray/array_coercion.c | 10 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 4 |
2 files changed, 11 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/array_coercion.c b/numpy/core/src/multiarray/array_coercion.c index 13d6682f7..f77a4a898 100644 --- a/numpy/core/src/multiarray/array_coercion.c +++ b/numpy/core/src/multiarray/array_coercion.c @@ -1395,8 +1395,13 @@ PyArray_DiscoverDTypeAndShape( * @return 1 if this is not a concrete dtype instance 0 otherwise */ static int -descr_is_legacy_parametric_instance(PyArray_Descr *descr) +descr_is_legacy_parametric_instance(PyArray_Descr *descr, + PyArray_DTypeMeta *DType) { + if (!NPY_DT_is_legacy(DType)) { + return 0; + } + if (PyDataType_ISUNSIZED(descr)) { return 1; } @@ -1440,7 +1445,8 @@ PyArray_ExtractDTypeAndDescriptor(PyObject *dtype, (PyTypeObject *)&PyArrayDTypeMeta_Type)) { *out_DType = NPY_DTYPE(dtype); Py_INCREF(*out_DType); - if (!descr_is_legacy_parametric_instance((PyArray_Descr *)dtype)) { + if (!descr_is_legacy_parametric_instance((PyArray_Descr *)dtype, + *out_DType)) { *out_descr = (PyArray_Descr *)dtype; Py_INCREF(*out_descr); } diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 4f0bc7337..280cdb0c7 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -20,6 +20,7 @@ #include "common.h" #include "ctors.h" #include "convert_datatype.h" +#include "dtypemeta.h" #include "shape.h" #include "npy_buffer.h" #include "lowlevel_strided_loops.h" @@ -664,7 +665,8 @@ PyArray_NewFromDescr_int( /* Check datatype element size */ nbytes = descr->elsize; if (PyDataType_ISUNSIZED(descr)) { - if (!PyDataType_ISFLEXIBLE(descr)) { + if (!PyDataType_ISFLEXIBLE(descr) && + NPY_DT_is_legacy(NPY_DTYPE(descr))) { PyErr_SetString(PyExc_TypeError, "Empty data-type"); Py_DECREF(descr); return NULL; |