Skip to content

Commit

Permalink
CLN: de-duplicate numeric type check in _libs/testing (pandas-dev#36625)
Browse files Browse the repository at this point in the history
  • Loading branch information
arw2019 committed Oct 6, 2020
1 parent 01af08b commit f1adcd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
27 changes: 2 additions & 25 deletions pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,13 @@ from numpy cimport import_array

import_array()

from pandas._libs.util cimport is_array
from pandas._libs.lib import is_complex
from pandas._libs.util cimport is_array, is_real_number_object

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


cdef NUMERIC_TYPES = (
bool,
int,
float,
np.bool_,
np.int8,
np.int16,
np.int32,
np.int64,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
np.float16,
np.float32,
np.float64,
)


cdef bint is_comparable_as_number(obj):
return isinstance(obj, NUMERIC_TYPES)


cdef bint isiterable(obj):
return hasattr(obj, '__iter__')

Expand Down Expand Up @@ -200,7 +177,7 @@ cpdef assert_almost_equal(a, b,
# object comparison
return True

if is_comparable_as_number(a) and is_comparable_as_number(b):
if is_real_number_object(a) and is_real_number_object(b):
if array_equivalent(a, b, strict_nan=True):
# inf comparison
return True
Expand Down
4 changes: 4 additions & 0 deletions pandas/_libs/tslibs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ cdef inline bint is_bool_object(object obj) nogil:
PyObject_TypeCheck(obj, &PyBoolArrType_Type))


cdef inline bint is_real_number_object(object obj) nogil:
return is_bool_object(obj) or is_integer_object(obj) or is_float_object(obj)


cdef inline bint is_timedelta64_object(object obj) nogil:
"""
Cython equivalent of `isinstance(val, np.timedelta64)`
Expand Down

0 comments on commit f1adcd1

Please sign in to comment.