From ff8ecd1c472eb894658d3c5e807282b843f6855e Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Mon, 19 Dec 2016 18:15:50 -0500 Subject: [PATCH] PERF: make all inference routines cpdef bint --- pandas/lib.pyx | 10 ++++---- pandas/src/inference.pyx | 50 +++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/pandas/lib.pyx b/pandas/lib.pyx index 548a96780d37a..761969491cfc7 100644 --- a/pandas/lib.pyx +++ b/pandas/lib.pyx @@ -257,7 +257,7 @@ cdef double INF = 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): @@ -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): @@ -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. diff --git a/pandas/src/inference.pyx b/pandas/src/inference.pyx index a8b694d7ba008..2e6cfe7c7e9ad 100644 --- a/pandas/src/inference.pyx +++ b/pandas/src/inference.pyx @@ -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', @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: @@ -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: @@ -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. @@ -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: @@ -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: @@ -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 @@ -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 @@ -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 @@ -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: