Skip to content

Commit a618bec

Browse files
jbrockmendeljowens
authored andcommitted
Replace imports of * with explicit imports (pandas-dev#17269)
xref pandas-dev#17234
1 parent aa97aa6 commit a618bec

10 files changed

+106
-43
lines changed

pandas/_libs/hashtable.pyx

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@
22

33
from cpython cimport PyObject, Py_INCREF, PyList_Check, PyTuple_Check
44

5-
from khash cimport *
5+
from khash cimport (
6+
khiter_t,
7+
8+
kh_str_t, kh_init_str, kh_put_str, kh_exist_str,
9+
kh_get_str, kh_destroy_str, kh_resize_str,
10+
11+
kh_put_strbox, kh_get_strbox, kh_init_strbox,
12+
13+
kh_int64_t, kh_init_int64, kh_resize_int64, kh_destroy_int64,
14+
kh_get_int64, kh_exist_int64, kh_put_int64,
15+
16+
kh_float64_t, kh_exist_float64, kh_put_float64, kh_init_float64,
17+
kh_get_float64, kh_destroy_float64, kh_resize_float64,
18+
19+
kh_resize_uint64, kh_exist_uint64, kh_destroy_uint64, kh_put_uint64,
20+
kh_get_uint64, kh_init_uint64,
21+
22+
kh_destroy_pymap, kh_exist_pymap, kh_init_pymap, kh_get_pymap,
23+
kh_put_pymap, kh_resize_pymap)
24+
25+
626
from numpy cimport *
727

828
from libc.stdlib cimport malloc, free

pandas/_libs/index.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# cython: profile=False
22

3-
from numpy cimport ndarray
4-
5-
from numpy cimport (float64_t, int32_t, int64_t, uint8_t,
3+
from numpy cimport (ndarray, float64_t, int32_t, int64_t, uint8_t, uint64_t,
64
NPY_DATETIME, NPY_TIMEDELTA)
75
cimport cython
86

@@ -16,7 +14,9 @@ cimport util
1614
import numpy as np
1715

1816
cimport tslib
19-
from hashtable cimport *
17+
18+
from hashtable cimport HashTable
19+
2020
from pandas._libs import tslib, algos, hashtable as _hash
2121
from pandas._libs.tslib import Timestamp, Timedelta
2222
from datetime import datetime, timedelta

pandas/_libs/join_func_helper.pxi.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
99
# asof_join_by
1010
#----------------------------------------------------------------------
1111

12+
from hashtable cimport PyObjectHashTable, UInt64HashTable, Int64HashTable
13+
1214
{{py:
1315

1416
# table_type, by_dtype
@@ -23,7 +25,6 @@ on_dtypes = ['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t',
2325
}}
2426

2527

26-
from hashtable cimport *
2728

2829
{{for table_type, by_dtype in by_dtypes}}
2930
{{for on_dtype in on_dtypes}}

pandas/_libs/lib.pyx

+14-10
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@ from numpy cimport *
1010

1111
np.import_array()
1212

13-
cdef extern from "numpy/arrayobject.h":
14-
cdef enum NPY_TYPES:
15-
NPY_intp "NPY_INTP"
16-
1713
from libc.stdlib cimport malloc, free
1814

19-
from cpython cimport (PyDict_New, PyDict_GetItem, PyDict_SetItem,
20-
PyDict_Contains, PyDict_Keys,
21-
Py_INCREF, PyTuple_SET_ITEM,
15+
from cpython cimport (Py_INCREF, PyTuple_SET_ITEM,
2216
PyList_Check, PyFloat_Check,
2317
PyString_Check,
2418
PyBytes_Check,
25-
PyTuple_SetItem,
19+
PyUnicode_Check,
2620
PyTuple_New,
27-
PyObject_SetAttrString,
2821
PyObject_RichCompareBool,
2922
PyBytes_GET_SIZE,
3023
PyUnicode_GET_SIZE,
@@ -55,7 +48,18 @@ cdef double NAN = nan
5548
from datetime import datetime as pydatetime
5649

5750
# this is our tseries.pxd
58-
from datetime cimport *
51+
from datetime cimport (
52+
get_timedelta64_value, get_datetime64_value,
53+
npy_timedelta, npy_datetime,
54+
PyDateTime_Check, PyDate_Check, PyTime_Check, PyDelta_Check,
55+
PyDateTime_GET_YEAR,
56+
PyDateTime_GET_MONTH,
57+
PyDateTime_GET_DAY,
58+
PyDateTime_DATE_GET_HOUR,
59+
PyDateTime_DATE_GET_MINUTE,
60+
PyDateTime_DATE_GET_SECOND,
61+
PyDateTime_IMPORT)
62+
5963

6064
from tslib cimport (convert_to_tsobject, convert_to_timedelta64,
6165
_check_all_nulls)

pandas/_libs/parsers.pyx

+9-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cdef extern from "stdlib.h":
3232
cimport cython
3333
cimport numpy as cnp
3434

35-
from numpy cimport ndarray, uint8_t, uint64_t
35+
from numpy cimport ndarray, uint8_t, uint64_t, int64_t
3636

3737
import numpy as np
3838
cimport util
@@ -57,7 +57,14 @@ import os
5757

5858
cnp.import_array()
5959

60-
from khash cimport *
60+
from khash cimport (
61+
khiter_t,
62+
kh_str_t, kh_init_str, kh_put_str, kh_exist_str,
63+
kh_get_str, kh_destroy_str,
64+
kh_float64_t, kh_get_float64, kh_destroy_float64,
65+
kh_put_float64, kh_init_float64,
66+
kh_strbox_t, kh_put_strbox, kh_get_strbox, kh_init_strbox,
67+
kh_destroy_strbox)
6168

6269
import sys
6370

pandas/_libs/period.pyx

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from datetime import datetime, date, timedelta
22
import operator
33

44
from cpython cimport (
5+
PyUnicode_Check,
56
PyObject_RichCompareBool,
67
Py_EQ, Py_NE)
78

@@ -18,7 +19,16 @@ from pandas import compat
1819
from pandas.compat import PY2
1920

2021
cimport cython
21-
from datetime cimport *
22+
23+
from datetime cimport (
24+
is_leapyear,
25+
PyDateTime_IMPORT,
26+
pandas_datetimestruct,
27+
pandas_datetimestruct_to_datetime,
28+
pandas_datetime_to_datetimestruct,
29+
PANDAS_FR_ns,
30+
INT32_MIN)
31+
2232
cimport util, lib
2333
from lib cimport is_null_datetimelike, is_period
2434
from pandas._libs import tslib, lib

pandas/_libs/src/properties.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from cpython cimport PyDict_Contains, PyDict_GetItem, PyDict_GetItem
1+
from cpython cimport (
2+
PyDict_Contains, PyDict_GetItem, PyDict_GetItem, PyDict_SetItem)
23

34

45
cdef class cache_readonly(object):

pandas/_libs/src/skiplist.pyx

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
# Cython version: Wes McKinney
88

9-
cdef extern from "numpy/arrayobject.h":
10-
11-
void import_array()
12-
139
cdef extern from "math.h":
1410
double log(double x)
1511

@@ -25,7 +21,7 @@ import numpy as np
2521
from random import random
2622

2723
# initialize numpy
28-
import_array()
24+
np.import_array()
2925

3026
# TODO: optimize this, make less messy
3127

pandas/_libs/tslib.pyx

+35-17
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import warnings
44

55
cimport numpy as np
66
from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
7+
float64_t,
78
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
8-
from datetime cimport get_datetime64_value, get_timedelta64_value
99
import numpy as np
1010

1111
import sys
@@ -30,20 +30,47 @@ cdef extern from "datetime_helper.h":
3030
double total_seconds(object)
3131

3232
# this is our datetime.pxd
33-
from datetime cimport cmp_pandas_datetimestruct
3433
from libc.stdlib cimport free
3534

3635
from util cimport (is_integer_object, is_float_object, is_datetime64_object,
3736
is_timedelta64_object, INT64_MAX)
3837
cimport util
3938

40-
from datetime cimport *
41-
from khash cimport *
42-
cimport cython
43-
39+
# this is our datetime.pxd
40+
from datetime cimport (
41+
pandas_datetimestruct,
42+
pandas_datetime_to_datetimestruct,
43+
pandas_datetimestruct_to_datetime,
44+
cmp_pandas_datetimestruct,
45+
days_per_month_table,
46+
get_datetime64_value,
47+
get_timedelta64_value,
48+
get_datetime64_unit,
49+
PANDAS_DATETIMEUNIT,
50+
_string_to_dts,
51+
_pydatetime_to_dts,
52+
_date_to_datetime64,
53+
npy_datetime,
54+
is_leapyear,
55+
dayofweek,
56+
PANDAS_FR_ns,
57+
PyDateTime_Check, PyDate_Check,
58+
PyDateTime_IMPORT,
59+
timedelta, datetime
60+
)
61+
62+
# stdlib datetime imports
4463
from datetime import timedelta, datetime
4564
from datetime import time as datetime_time
4665

66+
from khash cimport (
67+
khiter_t,
68+
kh_destroy_int64, kh_put_int64,
69+
kh_init_int64, kh_int64_t,
70+
kh_resize_int64, kh_get_int64)
71+
72+
cimport cython
73+
4774
import re
4875

4976
# dateutil compat
@@ -81,15 +108,6 @@ PyDateTime_IMPORT
81108
cdef int64_t NPY_NAT = util.get_nat()
82109
iNaT = NPY_NAT
83110

84-
# < numpy 1.7 compat for NaT
85-
compat_NaT = np.array([NPY_NAT]).astype('m8[ns]').item()
86-
87-
88-
try:
89-
basestring
90-
except NameError: # py3
91-
basestring = str
92-
93111

94112
cdef inline object create_timestamp_from_ts(
95113
int64_t value, pandas_datetimestruct dts,
@@ -314,7 +332,7 @@ class Timestamp(_Timestamp):
314332
tz : string / timezone object, default None
315333
Timezone to localize to
316334
"""
317-
if isinstance(tz, basestring):
335+
if isinstance(tz, string_types):
318336
tz = maybe_get_tz(tz)
319337
return cls(datetime.now(tz))
320338

@@ -615,7 +633,7 @@ class Timestamp(_Timestamp):
615633
if self.tzinfo is None:
616634
# tz naive, localize
617635
tz = maybe_get_tz(tz)
618-
if not isinstance(ambiguous, basestring):
636+
if not isinstance(ambiguous, string_types):
619637
ambiguous = [ambiguous]
620638
value = tz_localize_to_utc(np.array([self.value], dtype='i8'), tz,
621639
ambiguous=ambiguous, errors=errors)[0]

pandas/_libs/window.pyx

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ cdef inline int int_min(int a, int b): return a if a <= b else b
5656

5757
from util cimport numeric
5858

59-
from skiplist cimport *
59+
from skiplist cimport (
60+
skiplist_t,
61+
skiplist_init,
62+
skiplist_destroy,
63+
skiplist_get,
64+
skiplist_insert,
65+
skiplist_remove)
6066

6167
cdef extern from "../src/headers/math.h":
6268
double sqrt(double x) nogil

0 commit comments

Comments
 (0)