Skip to content

Remove from numpy cimport * #17521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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 = <double> 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want libc.math here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Just pushed a fix.


# this is our util.pxd
from util cimport numeric, get_nat
Expand Down
7 changes: 4 additions & 3 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# cython: profile=False

from numpy cimport *
cimport numpy as np
Copy link
Contributor

@chris-b1 chris-b1 Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're inconsistent about this, but at least I prefer the cimport numpy as cnp, so it is clearer which parts need c-level access (edit: cnp)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming right up.

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
Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 3 additions & 18 deletions pandas/_libs/join.pyx
Original file line number Diff line number Diff line change
@@ -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 = <double> np.NaN
cdef double nan = NaN

Expand Down
23 changes: 4 additions & 19 deletions pandas/_libs/reshape.pyx
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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 = <double> np.NaN
cdef double nan = NaN

Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/src/reduce.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#cython=False
from numpy cimport *
import numpy as np

from distutils.version import LooseVersion
Expand Down