10000 BUG: raise error trying to coerce object arrays containing timedelta64('NaT') to StringDType by charris · Pull Request #26049 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: raise error trying to coerce object arrays containing timedelta64('NaT') to StringDType #26049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MNT: eliminate branching and duplication in is_known_scalar_type
  • Loading branch information
ngoldbaum authored and charris committed Mar 16, 2024
commit d2e36f2fcec883cf1dfdbc001a1ff668392c3ed6
23 changes: 7 additions & 16 deletions numpy/_core/src/multiarray/dtypemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,22 +838,13 @@ python_builtins_are_known_scalar_types(
* This is necessary only for python scalar classes which we discover
* as valid DTypes.
*/
if (pytype == &PyFloat_Type) {
return 1;
}
if (pytype == &PyLong_Type) {
return 1;
}
if (pytype == &PyBool_Type) {
return 1;
}
if (pytype == &PyComplex_Type) {
return 1;
}
if (pytype == &PyUnicode_Type) {
return 1;
}
if (pytype == &PyBytes_Type) {
if (pytype == &PyFloat_Type ||
pytype == &PyLong_Type ||
pytype == &PyBool_Type ||
pytype == &PyComplex_Type ||
pytype == &PyUnicode_Type ||
pytype == &PyBytes_Type)
{
return 1;
}
return 0;
Expand Down
107 changes: 26 additions & 81 deletions numpy/_core/src/multiarray/stringdtype/dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,91 +554,36 @@ stringdtype_get_clear_loop(void *NPY_UNUSED(traverse_context),
}

static int
stringdtype_is_known_scalar_type(PyArray_DTypeMeta *NPY_UNUSED(cls),
stringdtype_is_known_scalar_type(PyArray_DTypeMeta *cls,
PyTypeObject *pytype)
{
if (pytype == &PyFloat_Type) {
if (python_builtins_are_known_scalar_types(cls, pytype)) {
return 1;
}
if (pytype == &PyLong_Type) {
return 1;
}
if (pytype == &PyBool_Type) {
return 1;
}
if (pytype == &PyComplex_Type) {
return 1;
}
if (pytype == &PyUnicode_Type) {
return 1;
}
if (pytype == &PyBytes_Type) {
return 1;
}
if (pytype == &PyBoolArrType_Type) {
return 1;
}
if (pytype == &PyByteArrType_Type) {
return 1;
}
if (pytype == &PyShortArrType_Type) {
return 1;
}
if (pytype == &PyIntArrType_Type) {
return 1;
}
if (pytype == &PyLongArrType_Type) {
return 1;
}
if (pytype == &PyLongLongArrType_Type) {
return 1;
}
if (pytype == &PyUByteArrType_Type) {
return 1;
}
if (pytype == &PyUShortArrType_Type) {
return 1;
}
if (pytype == &PyUIntArrType_Type) {
return 1;
}
if (pytype == &PyULongArrType_Type) {
return 1;
}
if (pytype == &PyULongLongArrType_Type) {
return 1;
}
if (pytype == &PyHalfArrType_Type) {
return 1;
}
if (pytype == &PyFloatArrType_Type) {
return 1;
}
if (pytype == &PyDoubleArrType_Type) {
return 1;
}
if (pytype == &PyLongDoubleArrType_Type) {
return 1;
}
if (pytype == &PyCFloatArrType_Type) {
return 1;
}
if (pytype == &PyCDoubleArrType_Type) {
return 1;
}
if (pytype == &PyCLongDoubleArrType_Type) {
return 1;
}
if (pytype == &PyIntpArrType_Type) {
return 1;
}
if (pytype == &PyUIntpArrType_Type) {
return 1;
}
if (pytype == &PyDatetimeArrType_Type) {
return 1;
}
if (pytype == &PyTimedeltaArrType_Type) {
// accept every built-in numpy dtype
else if (pytype == &PyBoolArrType_Type ||
pytype == &PyByteArrType_Type ||
pytype == &PyShortArrType_Type ||
pytype == &PyIntArrType_Type ||
pytype == &PyLongArrType_Type ||
pytype == &PyLongLongArrType_Type ||
pytype == &PyUByteArrType_Type ||
pytype == &PyUShortArrType_Type ||
pytype == &PyUIntArrType_Type ||
pytype == &PyULongArrType_Type ||
pytype == &PyULongLongArrType_Type ||
pytype == &PyHalfArrType_Type ||
pytype == &PyFloatArrType_Type ||
pytype == &PyDoubleArrType_Type ||
pytype == &PyLongDoubleArrType_Type ||
pytype == &PyCFloatArrType_Type ||
pytype == &PyCDoubleArrType_Type ||
pytype == &PyCLongDoubleArrType_Type ||
pytype == &PyIntpArrType_Type ||
pytype == &PyUIntpArrType_Type ||
pytype == &PyDatetimeArrType_Type ||
pytype == &PyTimedeltaArrType_Type)
{
return 1;
}
return 0;
Expand Down
0