From 3b5bc42e86feb72f384c14c5e735446065e13790 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 14:52:12 -0700 Subject: [PATCH 01/12] remove star imports --- pandas/io/msgpack/_unpacker.pyx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pandas/io/msgpack/_unpacker.pyx b/pandas/io/msgpack/_unpacker.pyx index 427414b80dfe4..0c50aa5e68103 100644 --- a/pandas/io/msgpack/_unpacker.pyx +++ b/pandas/io/msgpack/_unpacker.pyx @@ -1,15 +1,23 @@ # coding: utf-8 # cython: embedsignature=True -from cpython cimport * +from cython cimport Py_ssize_t + +from cpython cimport ( + PyCallable_Check, + PyBUF_SIMPLE, PyObject_GetBuffer, PyBuffer_Release, + PyBytes_Size, + PyBytes_FromStringAndSize, + PyBytes_AsString) + cdef extern from "Python.h": ctypedef struct PyObject cdef int PyObject_AsReadBuffer(object o, const void** buff, Py_ssize_t* buf_len) except -1 -from libc.stdlib cimport * -from libc.string cimport * -from libc.limits cimport * +from libc.stdlib cimport free, malloc +from libc.string cimport memcpy, memmove +from libc.limits cimport INT_MAX from pandas.io.msgpack.exceptions import (BufferFull, OutOfData, UnpackValueError, ExtraData) From 57bcd294c75d04c275f048782dcbf40d91b7ddce Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 14:57:46 -0700 Subject: [PATCH 02/12] remove star imports --- pandas/io/msgpack/_packer.pyx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pandas/io/msgpack/_packer.pyx b/pandas/io/msgpack/_packer.pyx index c81069c8e04c0..697af3247aba8 100644 --- a/pandas/io/msgpack/_packer.pyx +++ b/pandas/io/msgpack/_packer.pyx @@ -1,10 +1,16 @@ # coding: utf-8 # cython: embedsignature=True -from cpython cimport * -from libc.stdlib cimport * -from libc.string cimport * -from libc.limits cimport * +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 libc.stdlib cimport free, malloc from pandas.io.msgpack.exceptions import PackValueError from pandas.io.msgpack import ExtType From 1748378e077635b93dd8a898de2d672623f0603a Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 14:59:51 -0700 Subject: [PATCH 03/12] fix type, remove unused cimport --- pandas/io/msgpack/_packer.pyx | 2 +- pandas/io/sas/sas.pyx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/io/msgpack/_packer.pyx b/pandas/io/msgpack/_packer.pyx index 697af3247aba8..d67c632188e62 100644 --- a/pandas/io/msgpack/_packer.pyx +++ b/pandas/io/msgpack/_packer.pyx @@ -80,7 +80,7 @@ cdef class Packer(object): cdef object _berrors cdef char *encoding cdef char *unicode_errors - cdef bool use_float + cdef bint use_float cdef bint autoreset def __cinit__(self): diff --git a/pandas/io/sas/sas.pyx b/pandas/io/sas/sas.pyx index 3d94dc127a1d2..f008ded087051 100644 --- a/pandas/io/sas/sas.pyx +++ b/pandas/io/sas/sas.pyx @@ -2,8 +2,7 @@ # cython: boundscheck=False, initializedcheck=False import numpy as np -cimport numpy as cnp -from numpy cimport uint8_t, uint16_t, int8_t, int64_t, ndarray +from numpy cimport uint8_t, uint16_t, int64_t, ndarray import sas_constants as const # rle_decompress decompresses data using a Run Length Encoding From 49af513715f495121643b158907b7e29213a2976 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 15:03:13 -0700 Subject: [PATCH 04/12] remove unused cimports --- pandas/_libs/writers.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/_libs/writers.pyx b/pandas/_libs/writers.pyx index 77d8ca81258a0..041eb59812ae3 100644 --- a/pandas/_libs/writers.pyx +++ b/pandas/_libs/writers.pyx @@ -12,9 +12,7 @@ except ImportError: from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE import numpy as np -cimport numpy as cnp from numpy cimport ndarray, uint8_t -cnp.import_array() ctypedef fused pandas_string: From 0be3c94c2326e5010bc74c6ad4c21e77329b2f3a Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 15:04:48 -0700 Subject: [PATCH 05/12] remove unused cimports --- pandas/_libs/tslibs/parsing.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 580d155f87fa8..ffa3d8df44be8 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -14,9 +14,7 @@ from cpython.datetime cimport datetime import time import numpy as np -cimport numpy as cnp -from numpy cimport int64_t, ndarray -cnp.import_array() +from numpy cimport ndarray # Avoid import from outside _libs if sys.version_info.major == 2: From 457de6820c6815cee7e0c5dc8dc2b9b988e51987 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 16:01:08 -0700 Subject: [PATCH 06/12] fix ignored exception, closes #22067 --- pandas/_libs/tslibs/period.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 4054154cd285b..65fb0f331d039 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1920,8 +1920,8 @@ class Period(_Period): return cls._from_ordinal(ordinal, freq) -cdef int64_t _ordinal_from_fields(year, month, quarter, day, - hour, minute, second, freq): +cdef int64_t _ordinal_from_fields(int year, int month, quarter, int day, + int hour, int minute, int second, freq): base, mult = get_freq_code(freq) if quarter is not None: year, month = quarter_to_myear(year, quarter, freq) From be6bd6389e1e650caf314ff08bdbf9650e7c8c6e Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 16:01:19 -0700 Subject: [PATCH 07/12] remove unused cimports --- pandas/_libs/hashing.pyx | 2 +- pandas/_libs/tslibs/resolution.pyx | 2 -- pandas/_libs/tslibs/strptime.pyx | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/_libs/hashing.pyx b/pandas/_libs/hashing.pyx index 4489847518a1d..ff92ee306288a 100644 --- a/pandas/_libs/hashing.pyx +++ b/pandas/_libs/hashing.pyx @@ -3,7 +3,7 @@ # at https://github.com/veorq/SipHash import cython -cimport numpy as cnp + import numpy as np from numpy cimport ndarray, uint8_t, uint32_t, uint64_t diff --git a/pandas/_libs/tslibs/resolution.pyx b/pandas/_libs/tslibs/resolution.pyx index 4b90c669eebba..0659e2a553e7e 100644 --- a/pandas/_libs/tslibs/resolution.pyx +++ b/pandas/_libs/tslibs/resolution.pyx @@ -5,9 +5,7 @@ cimport cython from cython cimport Py_ssize_t import numpy as np -cimport numpy as cnp from numpy cimport ndarray, int64_t, int32_t -cnp.import_array() from util cimport is_string_object, get_nat diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index a843a8e2b5612..de2b7440156a7 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -25,8 +25,6 @@ import pytz from cython cimport Py_ssize_t from cpython cimport PyFloat_Check -cimport cython - import numpy as np from numpy cimport ndarray, int64_t From baf99698656f4f93cfc0f10cd2c55c4c447287c1 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Jul 2018 16:08:54 -0700 Subject: [PATCH 08/12] remove unused cimports --- pandas/_libs/tslibs/frequencies.pyx | 2 -- pandas/_libs/window.pyx | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/tslibs/frequencies.pyx b/pandas/_libs/tslibs/frequencies.pyx index 7803595badee1..5c8efa8c03712 100644 --- a/pandas/_libs/tslibs/frequencies.pyx +++ b/pandas/_libs/tslibs/frequencies.pyx @@ -2,8 +2,6 @@ # cython: profile=False import re -cimport cython - cimport numpy as cnp cnp.import_array() diff --git a/pandas/_libs/window.pyx b/pandas/_libs/window.pyx index 6453b5ed2ab3a..efc8a02014bc0 100644 --- a/pandas/_libs/window.pyx +++ b/pandas/_libs/window.pyx @@ -9,7 +9,7 @@ from libc.stdlib cimport malloc, free import numpy as np cimport numpy as cnp -from numpy cimport ndarray, double_t, int64_t, float64_t +from numpy cimport ndarray, double_t, int64_t, float64_t, float32_t cnp.import_array() @@ -25,11 +25,11 @@ from skiplist cimport (skiplist_t, skiplist_init, skiplist_destroy, skiplist_get, skiplist_insert, skiplist_remove) -cdef cnp.float32_t MINfloat32 = np.NINF -cdef cnp.float64_t MINfloat64 = np.NINF +cdef float32_t MINfloat32 = np.NINF +cdef float64_t MINfloat64 = np.NINF -cdef cnp.float32_t MAXfloat32 = np.inf -cdef cnp.float64_t MAXfloat64 = np.inf +cdef float32_t MAXfloat32 = np.inf +cdef float64_t MAXfloat64 = np.inf cdef double NaN = np.NaN From 9766fcd0bdcc58f7439361ee231be4c656d74a3b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 28 Jul 2018 08:34:28 -0700 Subject: [PATCH 09/12] Test for 22067 --- .../tests/indexes/datetimes/test_datetime.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 1a5f12103595c..42d8db14025e9 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -1,4 +1,5 @@ import warnings +import sys import pytest @@ -8,7 +9,7 @@ import dateutil import pandas as pd import pandas.util.testing as tm -from pandas.compat import lrange +from pandas.compat import lrange, StringIO from pandas import (DatetimeIndex, Index, date_range, DataFrame, Timestamp, offsets) @@ -126,6 +127,22 @@ def test_map(self): exp = Index([f(x) for x in rng], dtype=' Date: Sat, 28 Jul 2018 08:49:11 -0700 Subject: [PATCH 10/12] flake8 fixups --- pandas/tests/indexes/datetimes/test_datetime.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 42d8db14025e9..b7024fbc55ad8 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -135,13 +135,13 @@ def test_map_fallthrough(self): stderr = sys.stderr sys.stderr = c try: - out = dti.map(lambda x: pd.Period(year=x.year, - month=x.month, freq='M')) + dti.map(lambda x: pd.Period(year=x.year, + month=x.month, freq='M')) finally: sys.stderr = stderr cv = c.getvalue() - assert cv == '' + assert cv == '' def test_iteration_preserves_tz(self): # see gh-8890 From af4b66ac3e628f97234a3c9718db0bd014de9079 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 29 Jul 2018 10:25:32 -0700 Subject: [PATCH 11/12] use tm.capture_stderr --- pandas/tests/indexes/datetimes/test_datetime.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index b7024fbc55ad8..e68ec3090414e 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -9,7 +9,7 @@ import dateutil import pandas as pd import pandas.util.testing as tm -from pandas.compat import lrange, StringIO +from pandas.compat import lrange from pandas import (DatetimeIndex, Index, date_range, DataFrame, Timestamp, offsets) @@ -127,20 +127,15 @@ def test_map(self): exp = Index([f(x) for x in rng], dtype=' Date: Sun, 29 Jul 2018 13:57:27 -0700 Subject: [PATCH 12/12] dummy commit to force CI --- pandas/tests/indexes/datetimes/test_datetime.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index e68ec3090414e..2adf09924a509 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -132,8 +132,7 @@ def test_map_fallthrough(self): # GH#22067, check we don't get warnings about silently ignored errors dti = date_range('2017-01-01', '2018-01-01', freq='B') - dti.map(lambda x: pd.Period(year=x.year, - month=x.month, freq='M')) + dti.map(lambda x: pd.Period(year=x.year, month=x.month, freq='M')) cv = sys.stderr.getvalue() assert cv == ''