Skip to content

PERF: make all inference routines cpdef bint #14925

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions pandas/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ cdef double INF = <double> np.inf
cdef double NEGINF = -INF


cpdef checknull(object val):
cpdef bint checknull(object val):
if util.is_float_object(val) or util.is_complex_object(val):
return val != val # and val != INF and val != NEGINF
elif util.is_datetime64_object(val):
Expand All @@ -272,7 +272,7 @@ cpdef checknull(object val):
return _checknull(val)


cpdef checknull_old(object val):
cpdef bint checknull_old(object val):
if util.is_float_object(val) or util.is_complex_object(val):
return val != val or val == INF or val == NEGINF
elif util.is_datetime64_object(val):
Expand All @@ -287,21 +287,21 @@ cpdef checknull_old(object val):
return util._checknull(val)


cpdef isposinf_scalar(object val):
cpdef bint isposinf_scalar(object val):
if util.is_float_object(val) and val == INF:
return True
else:
return False


cpdef isneginf_scalar(object val):
cpdef bint isneginf_scalar(object val):
if util.is_float_object(val) and val == NEGINF:
return True
else:
return False


def isscalar(object val):
cpdef bint isscalar(object val):
"""
Return True if given value is scalar.

Expand Down
50 changes: 24 additions & 26 deletions pandas/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ from util cimport (UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX,
# core.common import for fast inference checks


def is_float(object obj):
cpdef bint is_float(object obj):
return util.is_float_object(obj)


def is_integer(object obj):
cpdef bint is_integer(object obj):
return util.is_integer_object(obj)


def is_bool(object obj):
cpdef bint is_bool(object obj):
return util.is_bool_object(obj)


def is_complex(object obj):
cpdef bint is_complex(object obj):
return util.is_complex_object(obj)


def is_decimal(object obj):
cpdef bint is_decimal(object obj):
return isinstance(obj, Decimal)


cpdef bint is_period(object val):
""" Return a boolean if this is a Period object """
return util.is_period_object(val)


_TYPE_MAP = {
'categorical': 'categorical',
'category': 'categorical',
Expand Down Expand Up @@ -234,7 +236,7 @@ def infer_dtype(object _values):
return 'mixed'


def is_possible_datetimelike_array(object arr):
cpdef bint is_possible_datetimelike_array(object arr):
# determine if we have a possible datetimelike (or null-like) array
cdef:
Py_ssize_t i, n = len(arr)
Expand Down Expand Up @@ -319,7 +321,7 @@ cdef inline bint is_timedelta(object o):
return PyDelta_Check(o) or util.is_timedelta64_object(o)


def is_bool_array(ndarray values):
cpdef bint is_bool_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -340,11 +342,7 @@ def is_bool_array(ndarray values):
return False


def is_integer(object o):
return util.is_integer_object(o)


def is_integer_array(ndarray values):
cpdef bint is_integer_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -365,7 +363,7 @@ def is_integer_array(ndarray values):
return False


def is_integer_float_array(ndarray values):
cpdef bint is_integer_float_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -388,7 +386,7 @@ def is_integer_float_array(ndarray values):
return False


def is_float_array(ndarray values):
cpdef bint is_float_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -409,7 +407,7 @@ def is_float_array(ndarray values):
return False


def is_string_array(ndarray values):
cpdef bint is_string_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -431,7 +429,7 @@ def is_string_array(ndarray values):
return False


def is_unicode_array(ndarray values):
cpdef bint is_unicode_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -452,7 +450,7 @@ def is_unicode_array(ndarray values):
return False


def is_bytes_array(ndarray values):
cpdef bint is_bytes_array(ndarray values):
cdef:
Py_ssize_t i, n = len(values)
ndarray[object] objbuf
Expand All @@ -473,7 +471,7 @@ def is_bytes_array(ndarray values):
return False


def is_datetime_array(ndarray[object] values):
cpdef bint is_datetime_array(ndarray[object] values):
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
if n == 0:
Expand All @@ -491,7 +489,7 @@ def is_datetime_array(ndarray[object] values):
return null_count != n


def is_datetime64_array(ndarray values):
cpdef bint is_datetime64_array(ndarray values):
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
if n == 0:
Expand All @@ -509,7 +507,7 @@ def is_datetime64_array(ndarray values):
return null_count != n


cpdef is_datetime_with_singletz_array(ndarray[object] values):
cpdef bint is_datetime_with_singletz_array(ndarray[object] values):
"""
Check values have the same tzinfo attribute.
Doesn't check values are datetime-like types.
Expand Down Expand Up @@ -537,7 +535,7 @@ cpdef is_datetime_with_singletz_array(ndarray[object] values):
return True


def is_timedelta_array(ndarray values):
cpdef bint is_timedelta_array(ndarray values):
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
if n == 0:
Expand All @@ -553,7 +551,7 @@ def is_timedelta_array(ndarray values):
return null_count != n


def is_timedelta64_array(ndarray values):
cpdef bint is_timedelta64_array(ndarray values):
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
if n == 0:
Expand All @@ -569,7 +567,7 @@ def is_timedelta64_array(ndarray values):
return null_count != n


def is_timedelta_or_timedelta64_array(ndarray values):
cpdef bint is_timedelta_or_timedelta64_array(ndarray values):
""" infer with timedeltas and/or nat/none """
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
Expand All @@ -586,7 +584,7 @@ def is_timedelta_or_timedelta64_array(ndarray values):
return null_count != n


def is_date_array(ndarray[object] values):
cpdef bint is_date_array(ndarray[object] values):
cdef Py_ssize_t i, n = len(values)
if n == 0:
return False
Expand All @@ -596,7 +594,7 @@ def is_date_array(ndarray[object] values):
return True


def is_time_array(ndarray[object] values):
cpdef bint is_time_array(ndarray[object] values):
cdef Py_ssize_t i, n = len(values)
if n == 0:
return False
Expand All @@ -606,7 +604,7 @@ def is_time_array(ndarray[object] values):
return True


def is_period_array(ndarray[object] values):
cpdef bint is_period_array(ndarray[object] values):
cdef Py_ssize_t i, null_count = 0, n = len(values)
cdef object v
if n == 0:
Expand Down