Skip to content

Commit

Permalink
Replace imports of * with explicit imports (pandas-dev#17269)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Aug 17, 2017
1 parent ecaac87 commit 95f4f7d
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 43 deletions.
22 changes: 21 additions & 1 deletion pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/join_func_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}
Expand Down
24 changes: 14 additions & 10 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
12 changes: 11 additions & 1 deletion pandas/_libs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from datetime import datetime, date, timedelta
import operator

from cpython cimport (
PyUnicode_Check,
PyObject_RichCompareBool,
Py_EQ, Py_NE)

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/src/properties.pyx
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 1 addition & 5 deletions pandas/_libs/src/skiplist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
52 changes: 35 additions & 17 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95f4f7d

Please sign in to comment.