File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
numpy/_core/src/multiarray Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -247,13 +247,17 @@ npy_discover_dtype_from_pytype(PyTypeObject *pytype)
247
247
}
248
248
249
249
/*
250
- * Note: This function never fails, but will return `NULL` for unknown scalars
251
- * and `None` for known array-likes (e.g. tuple, list, ndarray).
250
+ * Note: This function never fails, but will return `NULL` for unknown scalars or
251
+ * known array-likes (e.g. tuple, list, ndarray).
252
252
*/
253
253
NPY_NO_EXPORT PyObject *
254
254
PyArray_DiscoverDTypeFromScalarType (PyTypeObject * pytype )
255
255
{
256
- return (PyObject * )npy_discover_dtype_from_pytype (pytype );
256
+ PyObject * DType = (PyObject * )npy_discover_dtype_from_pytype (pytype );
257
+ if (DType == NULL || DType == Py_None ) {
258
+ return NULL ;
259
+ }
260
+ return DType ;
257
261
}
258
262
259
263
Original file line number Diff line number Diff line change 29
29
#include "npy_buffer.h"
30
30
#include "dtypemeta.h"
31
31
#include "stringdtype/dtype.h"
32
+ #include "array_coercion.h"
32
33
33
34
#ifndef PyDictProxy_Check
34
35
#define PyDictProxy_Check (obj ) (Py_TYPE(obj) == &PyDictProxy_Type)
@@ -1600,6 +1601,10 @@ _convert_from_type(PyObject *obj) {
1600
1601
return PyArray_DescrFromType (NPY_OBJECT );
1601
1602
}
1602
1603
else {
1604
+ PyObject * DType = PyArray_DiscoverDTypeFromScalarType (typ );
1605
+ if (DType != NULL ) {
1606
+ return PyArray_GetDefaultDescr ((PyArray_DTypeMeta * )DType );
1607
+ }
1603
1608
PyArray_Descr * ret = _try_convert_from_dtype_attr (obj );
1604
1609
if ((PyObject * )ret != Py_NotImplemented ) {
1605
1610
return ret ;
Original file line number Diff line number Diff line change @@ -390,6 +390,12 @@ PyArray_DescrFromTypeObject(PyObject *type)
390
390
Py_INCREF (type );
391
391
return (PyArray_Descr * )new ;
392
392
}
393
+
394
+ PyObject * DType = PyArray_DiscoverDTypeFromScalarType ((PyTypeObject * )type );
395
+ if (DType != NULL ) {
396
+ return PyArray_GetDefaultDescr ((PyArray_DTypeMeta * )DType );
397
+ }
398
+
393
399
return _descr_from_subtype (type );
394
400
}
395
401
You can’t perform that action at this time.
0 commit comments