Skip to content

Commit f1adcd1

Browse files
authored
CLN: de-duplicate numeric type check in _libs/testing (#36625)
1 parent 01af08b commit f1adcd1

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

pandas/_libs/testing.pyx

+2-25
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,13 @@ from numpy cimport import_array
77

88
import_array()
99

10-
from pandas._libs.util cimport is_array
1110
from pandas._libs.lib import is_complex
11+
from pandas._libs.util cimport is_array, is_real_number_object
1212

1313
from pandas.core.dtypes.common import is_dtype_equal
1414
from pandas.core.dtypes.missing import array_equivalent, isna
1515

1616

17-
cdef NUMERIC_TYPES = (
18-
bool,
19-
int,
20-
float,
21-
np.bool_,
22-
np.int8,
23-
np.int16,
24-
np.int32,
25-
np.int64,
26-
np.uint8,
27-
np.uint16,
28-
np.uint32,
29-
np.uint64,
30-
np.float16,
31-
np.float32,
32-
np.float64,
33-
)
34-
35-
36-
cdef bint is_comparable_as_number(obj):
37-
return isinstance(obj, NUMERIC_TYPES)
38-
39-
4017
cdef bint isiterable(obj):
4118
return hasattr(obj, '__iter__')
4219

@@ -200,7 +177,7 @@ cpdef assert_almost_equal(a, b,
200177
# object comparison
201178
return True
202179

203-
if is_comparable_as_number(a) and is_comparable_as_number(b):
180+
if is_real_number_object(a) and is_real_number_object(b):
204181
if array_equivalent(a, b, strict_nan=True):
205182
# inf comparison
206183
return True

pandas/_libs/tslibs/util.pxd

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ cdef inline bint is_bool_object(object obj) nogil:
121121
PyObject_TypeCheck(obj, &PyBoolArrType_Type))
122122

123123

124+
cdef inline bint is_real_number_object(object obj) nogil:
125+
return is_bool_object(obj) or is_integer_object(obj) or is_float_object(obj)
126+
127+
124128
cdef inline bint is_timedelta64_object(object obj) nogil:
125129
"""
126130
Cython equivalent of `isinstance(val, np.timedelta64)`

0 commit comments

Comments
 (0)