diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 67e0224b64d7f..5b705e80f97f5 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -25,7 +25,6 @@ from cpython.object cimport ( Py_EQ, PyObject, PyObject_RichCompareBool, - PyTypeObject, ) from cpython.ref cimport Py_INCREF from cpython.sequence cimport PySequence_Check @@ -67,10 +66,6 @@ from numpy cimport ( cnp.import_array() -cdef extern from "Python.h": - # Note: importing extern-style allows us to declare these as nogil - # functions, whereas `from cpython cimport` does not. - bint PyObject_TypeCheck(object obj, PyTypeObject* type) nogil cdef extern from "numpy/arrayobject.h": # cython's numpy.dtype specification is incorrect, which leads to @@ -89,9 +84,6 @@ cdef extern from "numpy/arrayobject.h": object fields tuple names - PyTypeObject PySignedIntegerArrType_Type - PyTypeObject PyUnsignedIntegerArrType_Type - cdef extern from "pandas/parser/pd_parser.h": int floatify(object, float64_t *result, int *maybe_int) except -1 void PandasParser_IMPORT() @@ -1437,14 +1429,12 @@ cdef class Seen: self.sint_ = ( self.sint_ or (oINT64_MIN <= val < 0) - # Cython equivalent of `isinstance(val, np.signedinteger)` - or PyObject_TypeCheck(val, &PySignedIntegerArrType_Type) + or isinstance(val, cnp.signedinteger) ) self.uint_ = ( self.uint_ or (oINT64_MAX < val <= oUINT64_MAX) - # Cython equivalent of `isinstance(val, np.unsignedinteger)` - or PyObject_TypeCheck(val, &PyUnsignedIntegerArrType_Type) + or isinstance(val, cnp.unsignedinteger) ) @property diff --git a/pandas/_libs/tslibs/util.pxd b/pandas/_libs/tslibs/util.pxd index 44ff322060dcb..2c39a2b4699b2 100644 --- a/pandas/_libs/tslibs/util.pxd +++ b/pandas/_libs/tslibs/util.pxd @@ -22,6 +22,7 @@ cdef extern from "Python.h": object PyUnicode_DecodeLocale(const char *str, const char *errors) nogil +cimport numpy as cnp from numpy cimport ( PyArray_Check, float64_t, @@ -54,7 +55,7 @@ cdef inline bint is_integer_object(object obj) noexcept: """ Cython equivalent of - `isinstance(val, (int, long, np.integer)) and not isinstance(val, bool)` + `isinstance(val, (int, np.integer)) and not isinstance(val, (bool, np.timedelta64))` Parameters ---------- @@ -68,13 +69,13 @@ cdef inline bint is_integer_object(object obj) noexcept: ----- This counts np.timedelta64 objects as integers. """ - return (not PyBool_Check(obj) and PyArray_IsIntegerScalar(obj) + return (not PyBool_Check(obj) and isinstance(obj, (int, cnp.integer)) and not is_timedelta64_object(obj)) cdef inline bint is_float_object(object obj) noexcept nogil: """ - Cython equivalent of `isinstance(val, (float, np.float64))` + Cython equivalent of `isinstance(val, (float, np.floating))` Parameters ---------- @@ -90,7 +91,7 @@ cdef inline bint is_float_object(object obj) noexcept nogil: cdef inline bint is_complex_object(object obj) noexcept nogil: """ - Cython equivalent of `isinstance(val, (complex, np.complex128))` + Cython equivalent of `isinstance(val, (complex, np.complexfloating))` Parameters ----------