diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 03f318d08d8cb..7f5fe85e07f40 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -1325,8 +1325,8 @@ 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: + 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