diff --git a/pandas/_libs/hashtable.pyx b/pandas/_libs/hashtable.pyx index 101e2c031f26e..2462b7af7b0fe 100644 --- a/pandas/_libs/hashtable.pyx +++ b/pandas/_libs/hashtable.pyx @@ -2,7 +2,27 @@ from cpython cimport PyObject, Py_INCREF, PyList_Check, PyTuple_Check -from khash cimport * +from khash cimport ( + khiter_t, + + kh_str_t, kh_init_str, kh_put_str, kh_exist_str, + kh_get_str, kh_destroy_str, kh_resize_str, + + kh_put_strbox, kh_get_strbox, kh_init_strbox, + + kh_int64_t, kh_init_int64, kh_resize_int64, kh_destroy_int64, + kh_get_int64, kh_exist_int64, kh_put_int64, + + kh_float64_t, kh_exist_float64, kh_put_float64, kh_init_float64, + kh_get_float64, kh_destroy_float64, kh_resize_float64, + + kh_resize_uint64, kh_exist_uint64, kh_destroy_uint64, kh_put_uint64, + kh_get_uint64, kh_init_uint64, + + kh_destroy_pymap, kh_exist_pymap, kh_init_pymap, kh_get_pymap, + kh_put_pymap, kh_resize_pymap) + + from numpy cimport * from libc.stdlib cimport malloc, free diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index b71963fdef1c1..42ba0c1cadaec 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -1,8 +1,6 @@ # cython: profile=False -from numpy cimport ndarray - -from numpy cimport (float64_t, int32_t, int64_t, uint8_t, +from numpy cimport (ndarray, float64_t, int32_t, int64_t, uint8_t, uint64_t, NPY_DATETIME, NPY_TIMEDELTA) cimport cython @@ -16,7 +14,9 @@ cimport util import numpy as np cimport tslib -from hashtable cimport * + +from hashtable cimport HashTable + from pandas._libs import tslib, algos, hashtable as _hash from pandas._libs.tslib import Timestamp, Timedelta from datetime import datetime, timedelta diff --git a/pandas/_libs/join_func_helper.pxi.in b/pandas/_libs/join_func_helper.pxi.in index 9cca9bba2a197..73d231b8588dc 100644 --- a/pandas/_libs/join_func_helper.pxi.in +++ b/pandas/_libs/join_func_helper.pxi.in @@ -9,6 +9,8 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in # asof_join_by #---------------------------------------------------------------------- +from hashtable cimport PyObjectHashTable, UInt64HashTable, Int64HashTable + {{py: # table_type, by_dtype @@ -23,7 +25,6 @@ on_dtypes = ['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', }} -from hashtable cimport * {{for table_type, by_dtype in by_dtypes}} {{for on_dtype in on_dtypes}} diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 0458d4ae9f3de..53ca41e4b2489 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -10,21 +10,14 @@ from numpy cimport * np.import_array() -cdef extern from "numpy/arrayobject.h": - cdef enum NPY_TYPES: - NPY_intp "NPY_INTP" - from libc.stdlib cimport malloc, free -from cpython cimport (PyDict_New, PyDict_GetItem, PyDict_SetItem, - PyDict_Contains, PyDict_Keys, - Py_INCREF, PyTuple_SET_ITEM, +from cpython cimport (Py_INCREF, PyTuple_SET_ITEM, PyList_Check, PyFloat_Check, PyString_Check, PyBytes_Check, - PyTuple_SetItem, + PyUnicode_Check, PyTuple_New, - PyObject_SetAttrString, PyObject_RichCompareBool, PyBytes_GET_SIZE, PyUnicode_GET_SIZE, @@ -55,7 +48,18 @@ cdef double NAN = nan from datetime import datetime as pydatetime # this is our tseries.pxd -from datetime cimport * +from datetime cimport ( + get_timedelta64_value, get_datetime64_value, + npy_timedelta, npy_datetime, + PyDateTime_Check, PyDate_Check, PyTime_Check, PyDelta_Check, + PyDateTime_GET_YEAR, + PyDateTime_GET_MONTH, + PyDateTime_GET_DAY, + PyDateTime_DATE_GET_HOUR, + PyDateTime_DATE_GET_MINUTE, + PyDateTime_DATE_GET_SECOND, + PyDateTime_IMPORT) + from tslib cimport (convert_to_tsobject, convert_to_timedelta64, _check_all_nulls) diff --git a/pandas/_libs/parsers.pyx b/pandas/_libs/parsers.pyx index ae420da2102b2..3e8b5c4bd3feb 100644 --- a/pandas/_libs/parsers.pyx +++ b/pandas/_libs/parsers.pyx @@ -32,7 +32,7 @@ cdef extern from "stdlib.h": cimport cython cimport numpy as cnp -from numpy cimport ndarray, uint8_t, uint64_t +from numpy cimport ndarray, uint8_t, uint64_t, int64_t import numpy as np cimport util @@ -57,7 +57,14 @@ import os cnp.import_array() -from khash cimport * +from khash cimport ( + khiter_t, + kh_str_t, kh_init_str, kh_put_str, kh_exist_str, + kh_get_str, kh_destroy_str, + kh_float64_t, kh_get_float64, kh_destroy_float64, + kh_put_float64, kh_init_float64, + kh_strbox_t, kh_put_strbox, kh_get_strbox, kh_init_strbox, + kh_destroy_strbox) import sys diff --git a/pandas/_libs/period.pyx b/pandas/_libs/period.pyx index 506fec28f5041..e017d863e1907 100644 --- a/pandas/_libs/period.pyx +++ b/pandas/_libs/period.pyx @@ -2,6 +2,7 @@ from datetime import datetime, date, timedelta import operator from cpython cimport ( + PyUnicode_Check, PyObject_RichCompareBool, Py_EQ, Py_NE) @@ -18,7 +19,16 @@ from pandas import compat from pandas.compat import PY2 cimport cython -from datetime cimport * + +from datetime cimport ( + is_leapyear, + PyDateTime_IMPORT, + pandas_datetimestruct, + pandas_datetimestruct_to_datetime, + pandas_datetime_to_datetimestruct, + PANDAS_FR_ns, + INT32_MIN) + cimport util, lib from lib cimport is_null_datetimelike, is_period from pandas._libs import tslib, lib diff --git a/pandas/_libs/src/properties.pyx b/pandas/_libs/src/properties.pyx index e619a3b6edd9a..4a3fd4b771a17 100644 --- a/pandas/_libs/src/properties.pyx +++ b/pandas/_libs/src/properties.pyx @@ -1,4 +1,5 @@ -from cpython cimport PyDict_Contains, PyDict_GetItem, PyDict_GetItem +from cpython cimport ( + PyDict_Contains, PyDict_GetItem, PyDict_GetItem, PyDict_SetItem) cdef class cache_readonly(object): diff --git a/pandas/_libs/src/skiplist.pyx b/pandas/_libs/src/skiplist.pyx index 3017931e25115..559b529822a69 100644 --- a/pandas/_libs/src/skiplist.pyx +++ b/pandas/_libs/src/skiplist.pyx @@ -6,10 +6,6 @@ # Cython version: Wes McKinney -cdef extern from "numpy/arrayobject.h": - - void import_array() - cdef extern from "math.h": double log(double x) @@ -25,7 +21,7 @@ import numpy as np from random import random # initialize numpy -import_array() +np.import_array() # TODO: optimize this, make less messy diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index e1ba4169ed629..32b8c92a50269 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -4,8 +4,8 @@ import warnings cimport numpy as np from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray, + float64_t, NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA) -from datetime cimport get_datetime64_value, get_timedelta64_value import numpy as np import sys @@ -30,20 +30,47 @@ cdef extern from "datetime_helper.h": double total_seconds(object) # this is our datetime.pxd -from datetime cimport cmp_pandas_datetimestruct from libc.stdlib cimport free from util cimport (is_integer_object, is_float_object, is_datetime64_object, is_timedelta64_object, INT64_MAX) cimport util -from datetime cimport * -from khash cimport * -cimport cython - +# this is our datetime.pxd +from datetime cimport ( + pandas_datetimestruct, + pandas_datetime_to_datetimestruct, + pandas_datetimestruct_to_datetime, + cmp_pandas_datetimestruct, + days_per_month_table, + get_datetime64_value, + get_timedelta64_value, + get_datetime64_unit, + PANDAS_DATETIMEUNIT, + _string_to_dts, + _pydatetime_to_dts, + _date_to_datetime64, + npy_datetime, + is_leapyear, + dayofweek, + PANDAS_FR_ns, + PyDateTime_Check, PyDate_Check, + PyDateTime_IMPORT, + timedelta, datetime + ) + +# stdlib datetime imports from datetime import timedelta, datetime from datetime import time as datetime_time +from khash cimport ( + khiter_t, + kh_destroy_int64, kh_put_int64, + kh_init_int64, kh_int64_t, + kh_resize_int64, kh_get_int64) + +cimport cython + import re # dateutil compat @@ -81,15 +108,6 @@ PyDateTime_IMPORT cdef int64_t NPY_NAT = util.get_nat() iNaT = NPY_NAT -# < numpy 1.7 compat for NaT -compat_NaT = np.array([NPY_NAT]).astype('m8[ns]').item() - - -try: - basestring -except NameError: # py3 - basestring = str - cdef inline object create_timestamp_from_ts( int64_t value, pandas_datetimestruct dts, @@ -314,7 +332,7 @@ class Timestamp(_Timestamp): tz : string / timezone object, default None Timezone to localize to """ - if isinstance(tz, basestring): + if isinstance(tz, string_types): tz = maybe_get_tz(tz) return cls(datetime.now(tz)) @@ -615,7 +633,7 @@ class Timestamp(_Timestamp): if self.tzinfo is None: # tz naive, localize tz = maybe_get_tz(tz) - if not isinstance(ambiguous, basestring): + if not isinstance(ambiguous, string_types): ambiguous = [ambiguous] value = tz_localize_to_utc(np.array([self.value], dtype='i8'), tz, ambiguous=ambiguous, errors=errors)[0] diff --git a/pandas/_libs/window.pyx b/pandas/_libs/window.pyx index bdd371871b6e1..9fb3d0662eb4f 100644 --- a/pandas/_libs/window.pyx +++ b/pandas/_libs/window.pyx @@ -56,7 +56,13 @@ cdef inline int int_min(int a, int b): return a if a <= b else b from util cimport numeric -from skiplist cimport * +from skiplist cimport ( + skiplist_t, + skiplist_init, + skiplist_destroy, + skiplist_get, + skiplist_insert, + skiplist_remove) cdef extern from "../src/headers/math.h": double sqrt(double x) nogil