From 9ed338e8e3acdec2e04ef91c07a8abeec2f247b3 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 4 Nov 2017 19:20:54 -0700 Subject: [PATCH 1/3] cleanup unused imports, constants --- pandas/_libs/lib.pyx | 23 +++++------- pandas/_libs/src/datetime.pxd | 69 +++------------------------------- pandas/_libs/src/inference.pyx | 2 +- pandas/_libs/src/reduce.pyx | 5 +-- 4 files changed, 18 insertions(+), 81 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index f882c3d7a7621..c89f5a5b780f3 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -8,7 +8,9 @@ cdef bint PY3 = (sys.version_info[0] >= 3) from numpy cimport * +# initialize numpy np.import_array() +np.import_ufunc() from libc.stdlib cimport malloc, free @@ -53,9 +55,7 @@ from datetime cimport get_timedelta64_value, get_datetime64_value from tslib cimport _check_all_nulls -import tslib -from tslib import NaT, Timestamp, Timedelta -import interval +from tslib import NaT, Timestamp, Timedelta, array_to_datetime from interval import Interval cdef int64_t NPY_NAT = util.get_nat() @@ -63,13 +63,8 @@ cdef int64_t NPY_NAT = util.get_nat() cimport util from util cimport is_array, _checknull, _checknan -cdef extern from "math.h": - double sqrt(double x) - double fabs(double) +from libc.math cimport sqrt, fabs -# initialize numpy -import_array() -import_ufunc() def values_from_object(object o): @@ -152,7 +147,7 @@ cpdef bint checknull_old(object val): elif is_array(val): return False else: - return util._checknull(val) + return _checknull(val) cpdef bint isposinf_scalar(object val): @@ -788,13 +783,13 @@ def scalar_binop(ndarray[object] values, object val, object op): object x result = np.empty(n, dtype=object) - if util._checknull(val): + if _checknull(val): result.fill(val) return result for i in range(n): x = values[i] - if util._checknull(x): + if _checknull(x): result[i] = x else: result[i] = op(x, val) @@ -821,9 +816,9 @@ def vec_binop(ndarray[object] left, ndarray[object] right, object op): try: result[i] = op(x, y) except TypeError: - if util._checknull(x): + if _checknull(x): result[i] = x - elif util._checknull(y): + elif _checknull(y): result[i] = y else: raise diff --git a/pandas/_libs/src/datetime.pxd b/pandas/_libs/src/datetime.pxd index 3c542a9d6410c..a5ba610dc89dc 100644 --- a/pandas/_libs/src/datetime.pxd +++ b/pandas/_libs/src/datetime.pxd @@ -1,60 +1,25 @@ # cython: profile=False -from numpy cimport int64_t, int32_t, npy_int64, npy_int32, ndarray -from cpython cimport PyObject +from numpy cimport int64_t, npy_int64, npy_int32 from cpython cimport PyUnicode_Check, PyUnicode_AsASCIIString -cdef extern from "datetime.h": - - ctypedef class datetime.date [object PyDateTime_Date]: - pass - - ctypedef class datetime.datetime [object PyDateTime_DateTime]: - pass - - ctypedef class datetime.timedelta [object PyDateTime_Delta]: - pass - - void PyDateTime_IMPORT() - - int PyDateTime_GET_YEAR(date) - int PyDateTime_GET_MONTH(date) - int PyDateTime_GET_DAY(date) - int PyDateTime_DATE_GET_HOUR(object o) - int PyDateTime_DATE_GET_MINUTE(object o) - int PyDateTime_DATE_GET_SECOND(object o) - int PyDateTime_DATE_GET_MICROSECOND(object o) - int PyDateTime_TIME_GET_HOUR(object o) - int PyDateTime_TIME_GET_MINUTE(object o) - int PyDateTime_TIME_GET_SECOND(object o) - int PyDateTime_TIME_GET_MICROSECOND(object o) - bint PyDateTime_Check(object o) - bint PyDate_Check(object o) - bint PyTime_Check(object o) - bint PyDelta_Check(object o) - object PyDateTime_FromDateAndTime(int year, int month, int day, int hour, - int minute, int second, int us) - cdef extern from "numpy/ndarrayobject.h": - ctypedef int64_t npy_timedelta ctypedef int64_t npy_datetime ctypedef enum NPY_CASTING: - NPY_NO_CASTING - NPY_EQUIV_CASTING - NPY_SAFE_CASTING - NPY_SAME_KIND_CASTING - NPY_UNSAFE_CASTING - + NPY_NO_CASTING + NPY_EQUIV_CASTING + NPY_SAFE_CASTING + NPY_SAME_KIND_CASTING + NPY_UNSAFE_CASTING cdef extern from "numpy_helper.h": npy_datetime get_datetime64_value(object o) npy_timedelta get_timedelta64_value(object o) cdef extern from "numpy/npy_common.h": - ctypedef unsigned char npy_bool cdef extern from "datetime/np_datetime.h": @@ -79,16 +44,12 @@ cdef extern from "datetime/np_datetime.h": npy_int64 year npy_int32 month, day, hour, min, sec, us, ps, as - int cmp_pandas_datetimestruct(pandas_datetimestruct *a, - pandas_datetimestruct *b) - npy_datetime pandas_datetimestruct_to_datetime(PANDAS_DATETIMEUNIT fr, pandas_datetimestruct *d) nogil void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr, pandas_datetimestruct *result) nogil int days_per_month_table[2][12] - pandas_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS int dayofweek(int y, int m, int d) nogil int is_leapyear(int64_t year) nogil @@ -102,10 +63,6 @@ cdef extern from "datetime/np_datetime_strings.h": PANDAS_DATETIMEUNIT *out_bestunit, npy_bool *out_special) - # int parse_python_string(object obj, pandas_datetimestruct *out) except -1 - - - cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts, int* out_local, int* out_tzoffset) except? -1: @@ -134,17 +91,3 @@ cdef inline int _cstring_to_dts(char *val, int length, NPY_UNSAFE_CASTING, dts, out_local, out_tzoffset, &out_bestunit, &special) return result - - -cdef inline bint check_dts_bounds(pandas_datetimestruct *dts): - """Returns True if an error needs to be raised""" - cdef: - bint error = False - - if (dts.year <= 1677 and - cmp_pandas_datetimestruct(dts, &_NS_MIN_DTS) == -1): - error = True - elif (dts.year >= 2262 and - cmp_pandas_datetimestruct(dts, &_NS_MAX_DTS) == 1): - error = True - return error diff --git a/pandas/_libs/src/inference.pyx b/pandas/_libs/src/inference.pyx index 5d550148b10bc..ec060335c220e 100644 --- a/pandas/_libs/src/inference.pyx +++ b/pandas/_libs/src/inference.pyx @@ -521,7 +521,7 @@ cpdef object infer_datetimelike_array(object arr): # convert *every* string array if len(objs): try: - tslib.array_to_datetime(objs, errors='raise') + array_to_datetime(objs, errors='raise') return 'datetime' except: pass diff --git a/pandas/_libs/src/reduce.pyx b/pandas/_libs/src/reduce.pyx index d1761384114ef..f0ec8d284ef0e 100644 --- a/pandas/_libs/src/reduce.pyx +++ b/pandas/_libs/src/reduce.pyx @@ -6,9 +6,8 @@ from distutils.version import LooseVersion is_numpy_prior_1_6_2 = LooseVersion(np.__version__) < '1.6.2' -cdef _get_result_array(object obj, - Py_ssize_t size, - Py_ssize_t cnt): + +cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt): if isinstance(obj, np.ndarray) \ or isinstance(obj, list) and len(obj) == cnt \ From fe5ab80c7197f2a5bc85e60b00699eb0e201b673 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 5 Nov 2017 08:26:18 -0800 Subject: [PATCH 2/3] whitespace fixup --- pandas/_libs/lib.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index c89f5a5b780f3..ca5b630e61aaf 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -66,7 +66,6 @@ from util cimport is_array, _checknull, _checknan from libc.math cimport sqrt, fabs - def values_from_object(object o): """ return my values or the object if we are say an ndarray """ cdef f From 86a80a68ec86101574b48883529993447e0ef2cb Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 5 Nov 2017 09:54:51 -0800 Subject: [PATCH 3/3] dummy commit to force CI --- pandas/_libs/properties.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/properties.pyx b/pandas/_libs/properties.pyx index 22d66356ebdc3..374da8067eedd 100644 --- a/pandas/_libs/properties.pyx +++ b/pandas/_libs/properties.pyx @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from cython cimport Py_ssize_t