From d549db786a49333c86835105809f49d4daf2f6a1 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 9 Dec 2019 14:39:26 +0200 Subject: [PATCH 1/2] Typing --- pandas/_libs/algos.pyx | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index c2d6a3bc4906d..1a0209e5ecd25 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -5,6 +5,8 @@ from libc.stdlib cimport malloc, free from libc.string cimport memmove from libc.math cimport fabs, sqrt +from typing import Tuple + import numpy as np cimport numpy as cnp from numpy cimport (ndarray, @@ -49,8 +51,9 @@ cdef inline bint are_diff(object left, object right): class Infinity: - """ provide a positive Infinity comparison method for ranking """ - + """ + Provide a positive Infinity comparison method for ranking. + """ __lt__ = lambda self, other: False __le__ = lambda self, other: isinstance(other, Infinity) __eq__ = lambda self, other: isinstance(other, Infinity) @@ -61,8 +64,9 @@ class Infinity: class NegInfinity: - """ provide a negative Infinity comparison method for ranking """ - + """ + Provide a negative Infinity comparison method for ranking. + """ __lt__ = lambda self, other: (not isinstance(other, NegInfinity) and not missing.checknull(other)) __le__ = lambda self, other: not missing.checknull(other) @@ -158,20 +162,19 @@ def groupsort_indexer(const int64_t[:] index, Py_ssize_t ngroups): Parameters ---------- index: int64 ndarray - mappings from group -> position + Mappings from group -> position. ngroups: int64 - number of groups + Number of groups. Returns ------- tuple - 1-d indexer ordered by groups, group counts + 1-d indexer ordered by groups, group counts. Notes ----- This is a reverse of the label factorization process. """ - cdef: Py_ssize_t i, loc, label, n ndarray[int64_t] counts, where, result @@ -674,12 +677,15 @@ def backfill_2d_inplace(algos_t[:, :] values, @cython.boundscheck(False) @cython.wraparound(False) -def is_monotonic(ndarray[algos_t, ndim=1] arr, bint timelike): +def is_monotonic(ndarray[algos_t, ndim=1] arr, + bint timelike) -> Tuple[bool, bool, bool]: """ Returns ------- tuple - is_monotonic_inc, is_monotonic_dec, is_unique + is_monotonic_inc : bool + is_monotonic_dec : bool + is_unique : bool """ cdef: Py_ssize_t i, n @@ -774,9 +780,8 @@ ctypedef fused rank_t: def rank_1d(rank_t[:] in_arr, ties_method='average', ascending=True, na_option='keep', pct=False): """ - Fast NaN-friendly version of scipy.stats.rankdata + Fast NaN-friendly version of ``scipy.stats.rankdata``. """ - cdef: Py_ssize_t i, j, n, dups = 0, total_tie_count = 0, non_na_idx = 0 @@ -995,9 +1000,8 @@ def rank_1d(rank_t[:] in_arr, ties_method='average', def rank_2d(rank_t[:, :] in_arr, axis=0, ties_method='average', ascending=True, na_option='keep', pct=False): """ - Fast NaN-friendly version of scipy.stats.rankdata + Fast NaN-friendly version of ``scipy.stats.rankdata``. """ - cdef: Py_ssize_t i, j, z, k, n, dups = 0, total_tie_count = 0 From e181b94ff5ac460e6c32614ec2dedf839013647f Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Tue, 10 Dec 2019 13:40:18 +0200 Subject: [PATCH 2/2] DOC: Cleaned docstrings --- pandas/_libs/algos.pyx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 1a0209e5ecd25..7a2fc9dc7845a 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -5,8 +5,6 @@ from libc.stdlib cimport malloc, free from libc.string cimport memmove from libc.math cimport fabs, sqrt -from typing import Tuple - import numpy as np cimport numpy as cnp from numpy cimport (ndarray, @@ -677,8 +675,7 @@ def backfill_2d_inplace(algos_t[:, :] values, @cython.boundscheck(False) @cython.wraparound(False) -def is_monotonic(ndarray[algos_t, ndim=1] arr, - bint timelike) -> Tuple[bool, bool, bool]: +def is_monotonic(ndarray[algos_t, ndim=1] arr, bint timelike): """ Returns -------