From e780538e1ed781be1cfc12a161d414021051bb7e Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 6 Apr 2020 13:26:20 +0300 Subject: [PATCH 1/3] CLN: Added static types for `pandas/_libs/reduction.pyx` --- pandas/_libs/reduction.pyx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 9f8579606014a..98452b1a2cb27 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -36,7 +36,12 @@ cdef class Reducer: object dummy, f, labels, typ, ityp, index ndarray arr - def __init__(self, ndarray arr, object f, axis=1, dummy=None, labels=None): + def __init__( + self, ndarray arr, object f, int axis=1, object dummy=None, object labels=None + ): + cdef: + Py_ssize_t n, k + n, k = (arr).shape if axis == 0: @@ -60,7 +65,7 @@ cdef class Reducer: self.dummy, self.typ, self.index, self.ityp = self._check_dummy( dummy=dummy) - cdef _check_dummy(self, dummy=None): + cdef _check_dummy(self, object dummy=None): cdef: object index = None, typ = None, ityp = None @@ -147,7 +152,7 @@ cdef class Reducer: cdef class _BaseGrouper: - cdef _check_dummy(self, dummy): + cdef _check_dummy(self, ndarray dummy): # both values and index must be an ndarray! values = dummy.values @@ -190,13 +195,16 @@ cdef class _BaseGrouper: """ Call self.f on our new group, then update to the next group. """ + cdef: + object res + cached_ityp._engine.clear_mapping() res = self.f(cached_typ) res = _extract_result(res) if not initialized: # On the first pass, we check the output shape to see # if this looks like a reduction. - initialized = 1 + initialized = True _check_result_array(res, len(self.dummy_arr)) islider.advance(group_size) @@ -535,6 +543,9 @@ cdef class BlockSlider: char **base_ptrs def __init__(self, frame): + cdef: + Py_ssize_t i, block + self.frame = frame self.dummy = frame[:0] self.index = self.dummy.index From f08a827c365cd831ba8424831e4d97749bf2cdba Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 6 Apr 2020 14:02:04 +0300 Subject: [PATCH 2/3] Fixed errors --- pandas/_libs/reduction.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 98452b1a2cb27..03813e410e7ab 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -542,9 +542,10 @@ cdef class BlockSlider: cdef: char **base_ptrs - def __init__(self, frame): + def __init__(self, object frame): cdef: - Py_ssize_t i, block + Py_ssize_t i + object b self.frame = frame self.dummy = frame[:0] From ceca15442b4f5027181bb9c1b352914013f8cd7a Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 6 Apr 2020 14:46:55 +0300 Subject: [PATCH 3/3] Fixed more errors --- pandas/_libs/reduction.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/reduction.pyx b/pandas/_libs/reduction.pyx index 03813e410e7ab..4a9c89848a9d8 100644 --- a/pandas/_libs/reduction.pyx +++ b/pandas/_libs/reduction.pyx @@ -152,7 +152,7 @@ cdef class Reducer: cdef class _BaseGrouper: - cdef _check_dummy(self, ndarray dummy): + cdef _check_dummy(self, object dummy): # both values and index must be an ndarray! values = dummy.values