Skip to content

Commit bad1e09

Browse files
authored
CLN: use cimports for type checks (#56002)
1 parent be81303 commit bad1e09

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

pandas/_libs/lib.pyx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ from cpython.object cimport (
2525
Py_EQ,
2626
PyObject,
2727
PyObject_RichCompareBool,
28-
PyTypeObject,
2928
)
3029
from cpython.ref cimport Py_INCREF
3130
from cpython.sequence cimport PySequence_Check
@@ -67,10 +66,6 @@ from numpy cimport (
6766

6867
cnp.import_array()
6968

70-
cdef extern from "Python.h":
71-
# Note: importing extern-style allows us to declare these as nogil
72-
# functions, whereas `from cpython cimport` does not.
73-
bint PyObject_TypeCheck(object obj, PyTypeObject* type) nogil
7469

7570
cdef extern from "numpy/arrayobject.h":
7671
# cython's numpy.dtype specification is incorrect, which leads to
@@ -89,9 +84,6 @@ cdef extern from "numpy/arrayobject.h":
8984
object fields
9085
tuple names
9186

92-
PyTypeObject PySignedIntegerArrType_Type
93-
PyTypeObject PyUnsignedIntegerArrType_Type
94-
9587
cdef extern from "pandas/parser/pd_parser.h":
9688
int floatify(object, float64_t *result, int *maybe_int) except -1
9789
void PandasParser_IMPORT()
@@ -1437,14 +1429,12 @@ cdef class Seen:
14371429
self.sint_ = (
14381430
self.sint_
14391431
or (oINT64_MIN <= val < 0)
1440-
# Cython equivalent of `isinstance(val, np.signedinteger)`
1441-
or PyObject_TypeCheck(val, &PySignedIntegerArrType_Type)
1432+
or isinstance(val, cnp.signedinteger)
14421433
)
14431434
self.uint_ = (
14441435
self.uint_
14451436
or (oINT64_MAX < val <= oUINT64_MAX)
1446-
# Cython equivalent of `isinstance(val, np.unsignedinteger)`
1447-
or PyObject_TypeCheck(val, &PyUnsignedIntegerArrType_Type)
1437+
or isinstance(val, cnp.unsignedinteger)
14481438
)
14491439

14501440
@property

pandas/_libs/tslibs/util.pxd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cdef extern from "Python.h":
2222
object PyUnicode_DecodeLocale(const char *str, const char *errors) nogil
2323

2424

25+
cimport numpy as cnp
2526
from numpy cimport (
2627
PyArray_Check,
2728
float64_t,
@@ -54,7 +55,7 @@ cdef inline bint is_integer_object(object obj) noexcept:
5455
"""
5556
Cython equivalent of
5657
57-
`isinstance(val, (int, long, np.integer)) and not isinstance(val, bool)`
58+
`isinstance(val, (int, np.integer)) and not isinstance(val, (bool, np.timedelta64))`
5859
5960
Parameters
6061
----------
@@ -68,13 +69,13 @@ cdef inline bint is_integer_object(object obj) noexcept:
6869
-----
6970
This counts np.timedelta64 objects as integers.
7071
"""
71-
return (not PyBool_Check(obj) and PyArray_IsIntegerScalar(obj)
72+
return (not PyBool_Check(obj) and isinstance(obj, (int, cnp.integer))
7273
and not is_timedelta64_object(obj))
7374

7475

7576
cdef inline bint is_float_object(object obj) noexcept nogil:
7677
"""
77-
Cython equivalent of `isinstance(val, (float, np.float64))`
78+
Cython equivalent of `isinstance(val, (float, np.floating))`
7879
7980
Parameters
8081
----------
@@ -90,7 +91,7 @@ cdef inline bint is_float_object(object obj) noexcept nogil:
9091

9192
cdef inline bint is_complex_object(object obj) noexcept nogil:
9293
"""
93-
Cython equivalent of `isinstance(val, (complex, np.complex128))`
94+
Cython equivalent of `isinstance(val, (complex, np.complexfloating))`
9495
9596
Parameters
9697
----------

0 commit comments

Comments
 (0)