From d50936018c924a3a26b76f0d9f0edcfb7ef355d0 Mon Sep 17 00:00:00 2001 From: "Francis T. O'Donovan" Date: Tue, 14 Nov 2017 10:54:14 -0500 Subject: [PATCH] BUG: Use float64 for row counter in rank() GH18271 As reported in #18271, for a large `Series` `s` of `float`s, `Series.rank(pct=True).max()` may not be `<=1` as expected. This is due to the use of a `float` for the row counter. This updates the counter to use a `float64`. --- doc/source/whatsnew/v0.21.1.txt | 2 +- pandas/_libs/algos_rank_helper.pxi.in | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.21.1.txt b/doc/source/whatsnew/v0.21.1.txt index 793e9bf17bac9..b0a8dd724bd9c 100644 --- a/doc/source/whatsnew/v0.21.1.txt +++ b/doc/source/whatsnew/v0.21.1.txt @@ -117,7 +117,7 @@ Reshaping Numeric ^^^^^^^ -- +- Fixed incorrect maximum :func:`Series.rank` percentile for large arrays (:issue:`18271`) - - diff --git a/pandas/_libs/algos_rank_helper.pxi.in b/pandas/_libs/algos_rank_helper.pxi.in index 0945aec638b1d..df659ef56f82d 100644 --- a/pandas/_libs/algos_rank_helper.pxi.in +++ b/pandas/_libs/algos_rank_helper.pxi.in @@ -60,7 +60,7 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average', ascending=True, float64_t sum_ranks = 0 int tiebreak = 0 bint keep_na = 0 - float count = 0.0 + float64_t count = 0.0 tiebreak = tiebreakers[ties_method] {{if dtype == 'float64'}} @@ -234,7 +234,7 @@ def rank_2d_{{dtype}}(object in_arr, axis=0, ties_method='average', float64_t sum_ranks = 0 int tiebreak = 0 bint keep_na = 0 - float count = 0.0 + float64_t count = 0.0 tiebreak = tiebreakers[ties_method]