From be6ccf30ecfe2b2954ab4ed98c87696cf0951982 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Tue, 24 Mar 2020 01:24:25 +0200 Subject: [PATCH] CLN/STY: Nitpicks Things I find myself doing in multiple branches --- pandas/_libs/algos.pyx | 39 ++++++++++++++++++++++++++++--------- pandas/_libs/index.pyx | 21 ++++++++++++++------ pandas/_libs/indexing.pyx | 3 ++- pandas/_libs/interval.pyx | 23 ++++++++++++++++++---- pandas/_libs/ops.pyx | 12 ++++++++++-- pandas/_libs/properties.pyx | 3 +-- 6 files changed, 77 insertions(+), 24 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index b7f17aee35a44..7a32b8957003e 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -38,8 +38,15 @@ cimport pandas._libs.util as util from pandas._libs.util cimport numeric, get_nat from pandas._libs.khash cimport ( - khiter_t, kh_destroy_int64, kh_put_int64, kh_init_int64, kh_int64_t, - kh_resize_int64, kh_get_int64) + kh_destroy_int64, + kh_get_int64, + kh_init_int64, + kh_int64_t, + kh_put_int64, + kh_resize_int64, + khiter_t, +) + import pandas._libs.missing as missing @@ -791,8 +798,13 @@ ctypedef fused rank_t: @cython.wraparound(False) @cython.boundscheck(False) -def rank_1d(rank_t[:] in_arr, ties_method='average', - ascending=True, na_option='keep', pct=False): +def rank_1d( + rank_t[:] in_arr, + ties_method="average", + bint ascending=True, + na_option="keep", + bint pct=False, +): """ Fast NaN-friendly version of ``scipy.stats.rankdata``. """ @@ -1009,8 +1021,14 @@ def rank_1d(rank_t[:] in_arr, ties_method='average', return ranks -def rank_2d(rank_t[:, :] in_arr, axis=0, ties_method='average', - ascending=True, na_option='keep', pct=False): +def rank_2d( + rank_t[:, :] in_arr, + int axis=0, + ties_method="average", + bint ascending=True, + na_option="keep", + bint pct=False, +): """ Fast NaN-friendly version of ``scipy.stats.rankdata``. """ @@ -1190,9 +1208,12 @@ ctypedef fused out_t: @cython.boundscheck(False) @cython.wraparound(False) -def diff_2d(diff_t[:, :] arr, - out_t[:, :] out, - Py_ssize_t periods, int axis): +def diff_2d( + diff_t[:, :] arr, + out_t[:, :] out, + Py_ssize_t periods, + int axis, +): cdef: Py_ssize_t i, j, sx, sy, start, stop bint f_contig = arr.is_f_contig() diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index 0ba5cb7e9bc40..4d26842cc0277 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -2,10 +2,19 @@ import warnings import numpy as np cimport numpy as cnp -from numpy cimport (ndarray, intp_t, - float64_t, float32_t, - int64_t, int32_t, int16_t, int8_t, - uint64_t, uint32_t, uint16_t, uint8_t +from numpy cimport ( + float32_t, + float64_t, + int8_t, + int16_t, + int32_t, + int64_t, + intp_t, + ndarray, + uint8_t, + uint16_t, + uint32_t, + uint64_t, ) cnp.import_array() @@ -364,7 +373,7 @@ cdef class ObjectEngine(IndexEngine): cdef class DatetimeEngine(Int64Engine): - cdef _get_box_dtype(self): + cdef str _get_box_dtype(self): return 'M8[ns]' cdef int64_t _unbox_scalar(self, scalar) except? -1: @@ -454,7 +463,7 @@ cdef class DatetimeEngine(Int64Engine): cdef class TimedeltaEngine(DatetimeEngine): - cdef _get_box_dtype(self): + cdef str _get_box_dtype(self): return 'm8[ns]' cdef int64_t _unbox_scalar(self, scalar) except? -1: diff --git a/pandas/_libs/indexing.pyx b/pandas/_libs/indexing.pyx index 316943edee124..f9aedeb8ad93e 100644 --- a/pandas/_libs/indexing.pyx +++ b/pandas/_libs/indexing.pyx @@ -2,7 +2,8 @@ cdef class _NDFrameIndexerBase: """ A base class for _NDFrameIndexer for fast instantiation and attribute access. """ - cdef public object obj, name, _ndim + cdef public: + object obj, name, _ndim def __init__(self, name, obj): self.obj = obj diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx index 2240c821cd239..6e41ff189592c 100644 --- a/pandas/_libs/interval.pyx +++ b/pandas/_libs/interval.pyx @@ -1,8 +1,16 @@ import numbers from operator import le, lt -from cpython.object cimport (Py_EQ, Py_NE, Py_GT, Py_LT, Py_GE, Py_LE, - PyObject_RichCompare) +from cpython.object cimport ( + Py_EQ, + Py_GE, + Py_GT, + Py_LE, + Py_LT, + Py_NE, + PyObject_RichCompare, +) + import cython from cython import Py_ssize_t @@ -10,9 +18,16 @@ from cython import Py_ssize_t import numpy as np cimport numpy as cnp from numpy cimport ( - int64_t, int32_t, float64_t, float32_t, uint64_t, + NPY_QUICKSORT, + PyArray_ArgSort, + PyArray_Take, + float32_t, + float64_t, + int32_t, + int64_t, ndarray, - PyArray_ArgSort, NPY_QUICKSORT, PyArray_Take) + uint64_t, +) cnp.import_array() diff --git a/pandas/_libs/ops.pyx b/pandas/_libs/ops.pyx index c0971b91a2fa1..658600cdfbe6c 100644 --- a/pandas/_libs/ops.pyx +++ b/pandas/_libs/ops.pyx @@ -1,7 +1,15 @@ import operator -from cpython.object cimport (PyObject_RichCompareBool, - Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE) +from cpython.object cimport ( + Py_EQ, + Py_GE, + Py_GT, + Py_LE, + Py_LT, + Py_NE, + PyObject_RichCompareBool, +) + import cython from cython import Py_ssize_t diff --git a/pandas/_libs/properties.pyx b/pandas/_libs/properties.pyx index 857119789ab45..0e04c5417cd7e 100644 --- a/pandas/_libs/properties.pyx +++ b/pandas/_libs/properties.pyx @@ -1,7 +1,6 @@ from cython import Py_ssize_t -from cpython.dict cimport ( - PyDict_Contains, PyDict_GetItem, PyDict_SetItem) +from cpython.dict cimport PyDict_Contains, PyDict_GetItem, PyDict_SetItem cdef class CachedProperty: