Skip to content

CLN: Update cpython imports in Cython Code GH28382 #28398

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 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cimport cython

from cpython cimport (PyObject, Py_INCREF,
PyMem_Malloc, PyMem_Realloc, PyMem_Free)
from cpython.ref cimport PyObject, Py_INCREF
from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free

from libc.stdlib cimport malloc, free

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cython
from cython import Py_ssize_t

from cpython cimport PyObject
from cpython.object cimport PyObject

cdef extern from "Python.h":
Py_ssize_t PY_SSIZE_T_MAX
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/khash.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from cpython cimport PyObject
from cpython.object cimport PyObject
from numpy cimport int64_t, uint64_t, int32_t, uint32_t, float64_t

cdef extern from "khash_python.h":
Expand Down
9 changes: 6 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import warnings
import cython
from cython import Py_ssize_t

from cpython cimport (Py_INCREF, PyTuple_SET_ITEM, PyTuple_New, PyObject_Str,
Py_EQ, Py_SIZE, PyObject_RichCompareBool,
PyUnicode_Join, PyList_New)
from cpython.list cimport PyList_New
from cpython.object cimport (PyObject_Str, PyObject_RichCompareBool, Py_EQ,
Py_SIZE)
from cpython.ref cimport Py_INCREF
from cpython.tuple cimport PyTuple_SET_ITEM, PyTuple_New
from cpython.unicode cimport PyUnicode_Join

from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
PyTime_Check, PyDelta_Check,
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/ops.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import operator

from cpython cimport (PyObject_RichCompareBool,
Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE)
from cpython.object cimport (PyObject_RichCompareBool,
Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE)

import cython
from cython import Py_ssize_t
Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ from libc.string cimport strncpy, strlen, strcasecmp
import cython
from cython import Py_ssize_t

from cpython cimport (PyObject, PyBytes_FromString,
PyBytes_AsString,
PyUnicode_AsUTF8String,
PyErr_Occurred, PyErr_Fetch,
PyUnicode_Decode)
from cpython.bytes cimport PyBytes_AsString, PyBytes_FromString
from cpython.exc cimport PyErr_Occurred, PyErr_Fetch
from cpython.object cimport PyObject
from cpython.ref cimport Py_XDECREF
from cpython.unicode cimport PyUnicode_AsUTF8String, PyUnicode_Decode


cdef extern from "Python.h":
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/properties.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cython import Py_ssize_t

from cpython cimport (
from cpython.dict cimport (
PyDict_Contains, PyDict_GetItem, PyDict_SetItem)


Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from distutils.version import LooseVersion

from cython import Py_ssize_t
from cpython cimport Py_INCREF
from cpython.ref cimport Py_INCREF

from libc.stdlib cimport malloc, free

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/c_timestamp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ shadows the python class, where we do any heavy lifting.

import warnings

from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)
from cpython.object cimport (PyObject_RichCompareBool, PyObject_RichCompare,
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)

import numpy as np
cimport numpy as cnp
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cpython cimport (
from cpython.object cimport (
PyObject_RichCompare,
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/np_datetime.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cpython cimport Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE
from cpython.object cimport Py_EQ, Py_NE, Py_GE, Py_GT, Py_LT, Py_LE

from cpython.datetime cimport (datetime, date,
PyDateTime_IMPORT,
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ from libc.string cimport strchr
import cython
from cython import Py_ssize_t

from cpython cimport PyObject_Str, PyUnicode_Join
from cpython.object cimport PyObject_Str
from cpython.unicode cimport PyUnicode_Join

from cpython.datetime cimport datetime, datetime_new, import_datetime
from cpython.version cimport PY_VERSION_HEX
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from cpython cimport (
from cpython.object cimport (
PyObject_RichCompareBool,
Py_EQ, Py_NE)

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import warnings

import cython

from cpython cimport Py_NE, Py_EQ, PyObject_RichCompare
from cpython.object cimport Py_NE, Py_EQ, PyObject_RichCompare

import numpy as np
cimport numpy as cnp
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/util.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from cpython cimport PyTypeObject
from cpython.object cimport PyTypeObject

cdef extern from *:
"""
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/writers.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import cython
from cython import Py_ssize_t

from cpython cimport PyBytes_GET_SIZE, PyUnicode_GET_SIZE
from cpython.bytes cimport PyBytes_GET_SIZE
from cpython.unicode cimport PyUnicode_GET_SIZE

import numpy as np
from numpy cimport ndarray, uint8_t
Expand Down
20 changes: 11 additions & 9 deletions pandas/io/msgpack/_packer.pyx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# coding: utf-8
# cython: embedsignature=True

from cpython cimport (
PyFloat_Check, PyLong_Check, PyInt_Check,
PyDict_CheckExact, PyDict_Check,
PyTuple_Check, PyList_Check,
PyCallable_Check,
PyUnicode_Check, PyBytes_Check,
PyBytes_AsString,
PyBytes_FromStringAndSize,
PyUnicode_AsEncodedString)
from cpython.bytes cimport (PyBytes_Check, PyBytes_AsString,
PyBytes_FromStringAndSize)
from cpython.dict cimport PyDict_Check, PyDict_CheckExact
from cpython.float cimport PyFloat_Check
from cpython.int cimport PyInt_Check
from cpython.list cimport PyList_Check
from cpython.long cimport PyLong_Check
from cpython.object cimport PyCallable_Check
from cpython.tuple cimport PyTuple_Check
from cpython.unicode cimport PyUnicode_Check, PyUnicode_AsEncodedString
Copy link
Member

Choose a reason for hiding this comment

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

doesnt need to be for this PR, but most/all of the PyFoo_Check calls can be replaced with their pure-python equivalents; cython will now automatically make the optimization

Copy link
Member

Choose a reason for hiding this comment

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

So basically replace this with isinstance checks right? I think OK as a separate PR @amunch if that's something you'd also like to tackle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I will replace these checks in a separate pull request.


from libc.stdlib cimport free, malloc

from pandas.io.msgpack.exceptions import PackValueError
Expand Down
11 changes: 5 additions & 6 deletions pandas/io/msgpack/_unpacker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

from cython cimport Py_ssize_t

from cpython cimport (
PyCallable_Check,
PyBUF_SIMPLE, PyObject_GetBuffer, PyBuffer_Release, Py_buffer,
PyBytes_Size,
PyBytes_FromStringAndSize,
PyBytes_AsString)
from cpython.buffer cimport (PyBUF_SIMPLE, PyObject_GetBuffer,
PyBuffer_Release, Py_buffer)
from cpython.bytes cimport (PyBytes_Size, PyBytes_AsString,
PyBytes_FromStringAndSize)
from cpython.object cimport PyCallable_Check

cdef extern from "Python.h":
ctypedef struct PyObject
Expand Down