From 1c241e7b0b2ddb62e5e44820f45cc06d683c1c76 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 13 Sep 2017 13:30:15 -0700 Subject: [PATCH 1/7] Remove from numpy cimport * --- pandas/_libs/algos.pyx | 32 ++++++++++---------------------- pandas/_libs/groupby.pyx | 7 ++++--- pandas/_libs/hashtable.pyx | 4 +--- pandas/_libs/interval.pyx | 3 +-- pandas/_libs/join.pyx | 21 +++------------------ pandas/_libs/reshape.pyx | 23 ++++------------------- pandas/_libs/src/reduce.pyx | 1 - 7 files changed, 23 insertions(+), 68 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 897a60e0c2f21..3942d04f8daff 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -1,10 +1,10 @@ # cython: profile=False -from numpy cimport * cimport numpy as np import numpy as np cimport cython +from cython cimport Py_ssize_t import_array() @@ -15,31 +15,19 @@ cimport util from libc.stdlib cimport malloc, free from libc.string cimport memmove -from numpy cimport NPY_INT8 as NPY_int8 -from numpy cimport NPY_INT16 as NPY_int16 -from numpy cimport NPY_INT32 as NPY_int32 -from numpy cimport NPY_INT64 as NPY_int64 -from numpy cimport NPY_FLOAT16 as NPY_float16 -from numpy cimport NPY_FLOAT32 as NPY_float32 -from numpy cimport NPY_FLOAT64 as NPY_float64 - -from numpy cimport (int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, - uint32_t, uint64_t, float16_t, float32_t, float64_t) - -int8 = np.dtype(np.int8) -int16 = np.dtype(np.int16) -int32 = np.dtype(np.int32) -int64 = np.dtype(np.int64) -float16 = np.dtype(np.float16) -float32 = np.dtype(np.float32) -float64 = np.dtype(np.float64) +from numpy cimport (ndarray, + NPY_INT64, NPY_UINT64, NPY_INT32, NPY_INT16, NPY_INT8, + NPY_FLOAT32, NPY_FLOAT64, + NPY_OBJECT, + int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, + uint32_t, uint64_t, float16_t, float32_t, float64_t, + double_t) + cdef double NaN = np.NaN cdef double nan = NaN -cdef extern from "../src/headers/math.h": - double sqrt(double x) nogil - double fabs(double) nogil +from cpython.math cimport sqrt, fabs # this is our util.pxd from util cimport numeric, get_nat diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index c6ff602cfef1c..d34c6c2285f7a 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -1,16 +1,17 @@ # cython: profile=False -from numpy cimport * cimport numpy as np import numpy as np cimport cython -import_array() +np.import_array() cimport util -from numpy cimport (int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, +from numpy cimport (ndarray, + double_t, + int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float16_t, float32_t, float64_t) from libc.stdlib cimport malloc, free diff --git a/pandas/_libs/hashtable.pyx b/pandas/_libs/hashtable.pyx index 2462b7af7b0fe..9aeb700dd5923 100644 --- a/pandas/_libs/hashtable.pyx +++ b/pandas/_libs/hashtable.pyx @@ -23,7 +23,7 @@ from khash cimport ( kh_put_pymap, kh_resize_pymap) -from numpy cimport * +from numpy cimport ndarray, uint8_t, uint32_t from libc.stdlib cimport malloc, free from cpython cimport (PyMem_Malloc, PyMem_Realloc, PyMem_Free, @@ -56,8 +56,6 @@ cdef extern from "datetime.h": PyDateTime_IMPORT -cdef extern from "Python.h": - int PySlice_Check(object) cdef size_t _INIT_VEC_CAP = 128 diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx index e287e1fc8bdaf..bfbda9696ff2b 100644 --- a/pandas/_libs/interval.pyx +++ b/pandas/_libs/interval.pyx @@ -1,11 +1,10 @@ cimport numpy as np import numpy as np -import pandas as pd cimport util cimport cython import cython -from numpy cimport * +from numpy cimport ndarray from tslib import Timestamp from cpython.object cimport (Py_EQ, Py_NE, Py_GT, Py_LT, Py_GE, Py_LE, diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index 385a9762ed90d..eddf1b43d1afa 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -1,34 +1,19 @@ # cython: profile=False -from numpy cimport * cimport numpy as np import numpy as np cimport cython +from cython cimport Py_ssize_t import_array() cimport util -from numpy cimport NPY_INT8 as NPY_int8 -from numpy cimport NPY_INT16 as NPY_int16 -from numpy cimport NPY_INT32 as NPY_int32 -from numpy cimport NPY_INT64 as NPY_int64 -from numpy cimport NPY_FLOAT16 as NPY_float16 -from numpy cimport NPY_FLOAT32 as NPY_float32 -from numpy cimport NPY_FLOAT64 as NPY_float64 - -from numpy cimport (int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, +from numpy cimport (ndarray, + int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float16_t, float32_t, float64_t) -int8 = np.dtype(np.int8) -int16 = np.dtype(np.int16) -int32 = np.dtype(np.int32) -int64 = np.dtype(np.int64) -float16 = np.dtype(np.float16) -float32 = np.dtype(np.float32) -float64 = np.dtype(np.float64) - cdef double NaN = np.NaN cdef double nan = NaN diff --git a/pandas/_libs/reshape.pyx b/pandas/_libs/reshape.pyx index 82851b7e80994..5ee3b3af786a8 100644 --- a/pandas/_libs/reshape.pyx +++ b/pandas/_libs/reshape.pyx @@ -1,34 +1,19 @@ # cython: profile=False -from numpy cimport * cimport numpy as np import numpy as np cimport cython +from cython cimport Py_ssize_t -import_array() +np.import_array() cimport util -from numpy cimport NPY_INT8 as NPY_int8 -from numpy cimport NPY_INT16 as NPY_int16 -from numpy cimport NPY_INT32 as NPY_int32 -from numpy cimport NPY_INT64 as NPY_int64 -from numpy cimport NPY_FLOAT16 as NPY_float16 -from numpy cimport NPY_FLOAT32 as NPY_float32 -from numpy cimport NPY_FLOAT64 as NPY_float64 - -from numpy cimport (int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, +from numpy cimport (ndarray, + int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float16_t, float32_t, float64_t) -int8 = np.dtype(np.int8) -int16 = np.dtype(np.int16) -int32 = np.dtype(np.int32) -int64 = np.dtype(np.int64) -float16 = np.dtype(np.float16) -float32 = np.dtype(np.float32) -float64 = np.dtype(np.float64) - cdef double NaN = np.NaN cdef double nan = NaN diff --git a/pandas/_libs/src/reduce.pyx b/pandas/_libs/src/reduce.pyx index 3ce94022e586b..f578eb2f4a346 100644 --- a/pandas/_libs/src/reduce.pyx +++ b/pandas/_libs/src/reduce.pyx @@ -1,5 +1,4 @@ #cython=False -from numpy cimport * import numpy as np from distutils.version import LooseVersion From 2d8ccb552604e7dff554241571bf4dd61a1dd37d Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 13 Sep 2017 16:19:26 -0700 Subject: [PATCH 2/7] Fixup cpython.math-->libc.math --- pandas/_libs/algos.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 3942d04f8daff..8e4af58c5459b 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -27,7 +27,7 @@ from numpy cimport (ndarray, cdef double NaN = np.NaN cdef double nan = NaN -from cpython.math cimport sqrt, fabs +from libc.math cimport sqrt, fabs # this is our util.pxd from util cimport numeric, get_nat From f4c987a5a06339b7b347d137d1fcbf30ae057878 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 13 Sep 2017 16:22:12 -0700 Subject: [PATCH 3/7] fixup whitespace --- pandas/_libs/reshape.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/reshape.pyx b/pandas/_libs/reshape.pyx index 5ee3b3af786a8..d6996add374a9 100644 --- a/pandas/_libs/reshape.pyx +++ b/pandas/_libs/reshape.pyx @@ -11,7 +11,7 @@ np.import_array() cimport util from numpy cimport (ndarray, - int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, + int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, float16_t, float32_t, float64_t) cdef double NaN = np.NaN From 6a8e86f26d7402bd62703cb1e220035a333884e3 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 13 Sep 2017 18:17:00 -0700 Subject: [PATCH 4/7] Fixup import_array-->np.import_array --- pandas/_libs/algos.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 8e4af58c5459b..8cbc65633c786 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -6,7 +6,7 @@ import numpy as np cimport cython from cython cimport Py_ssize_t -import_array() +np.import_array() cdef float64_t FP_ERR = 1e-13 From 8fb5e44040173fc0e7edc11b59d0669569db97a7 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 14 Sep 2017 09:06:57 -0700 Subject: [PATCH 5/7] fixup import_array-->np.import_array --- pandas/_libs/join.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index eddf1b43d1afa..503bdda75875f 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -6,7 +6,7 @@ import numpy as np cimport cython from cython cimport Py_ssize_t -import_array() +np.import_array() cimport util From e2f921d62da1bdf6fe5401016e7a39e58652cd20 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 14 Sep 2017 09:31:09 -0700 Subject: [PATCH 6/7] cimport numpy as np --> cimport numpy as cnp --- pandas/_libs/groupby.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index d34c6c2285f7a..9500e685367c8 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -1,11 +1,11 @@ # cython: profile=False -cimport numpy as np +cimport numpy as cnp import numpy as np cimport cython -np.import_array() +cnp.import_array() cimport util From 25520a3f0b22e20a4beff5a78abfe10ce6429821 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 15 Sep 2017 08:32:53 -0700 Subject: [PATCH 7/7] Add missing import in interval_tree --- pandas/_libs/intervaltree.pxi.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/intervaltree.pxi.in b/pandas/_libs/intervaltree.pxi.in index 4fa0d6d156fa2..b22e694c9fcca 100644 --- a/pandas/_libs/intervaltree.pxi.in +++ b/pandas/_libs/intervaltree.pxi.in @@ -4,11 +4,15 @@ Template for intervaltree WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in """ -from numpy cimport int64_t, float64_t -from numpy cimport ndarray, PyArray_ArgSort, NPY_QUICKSORT, PyArray_Take +from numpy cimport ( + int64_t, int32_t, float64_t, float32_t, + ndarray, + PyArray_ArgSort, NPY_QUICKSORT, PyArray_Take) import numpy as np cimport cython +from cython cimport Py_ssize_t + cimport numpy as cnp cnp.import_array()