From a1a832f81b4d27aecbb917b3b7ea828fddb8de66 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 5 May 2022 22:35:59 -0400 Subject: [PATCH 1/2] CLN: Remove special case for rank in groupby.ops --- pandas/_libs/groupby.pyx | 5 +++-- pandas/core/groupby/ops.py | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 03f318d08d8cb..10b26c65fff17 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -1325,8 +1325,9 @@ def group_rank( mask=sub_mask, ) for i in range(len(result)): - # TODO: why can't we do out[:, k] = result? - out[i, k] = result[i] + if labels[i] >= 0: + # TODO: why can't we do out[:, k] = result? + out[i, k] = result[i] # ---------------------------------------------------------------------- diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index a769c92e0b542..7285824f0111f 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -623,10 +623,6 @@ def _call_cython_op( result = result.T - if self.how == "rank" and self.has_dropped_na: - # TODO: Wouldn't need this if group_rank supported mask - result = np.where(comp_ids < 0, np.nan, result) - if self.how not in self.cast_blocklist: # e.g. if we are int64 and need to restore to datetime64/timedelta64 # "rank" is the only member of cast_blocklist we get here From 68ee19f2f55bc0ea9ba26a5cb09b0b2ff4e18d2e Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 6 May 2022 06:05:00 -0400 Subject: [PATCH 2/2] Remove TODO --- pandas/_libs/groupby.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 10b26c65fff17..7f5fe85e07f40 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -1326,7 +1326,6 @@ def group_rank( ) for i in range(len(result)): if labels[i] >= 0: - # TODO: why can't we do out[:, k] = result? out[i, k] = result[i]