Skip to content

Commit 64929a5

Browse files
committed
Fixed bug with First tiebreak across multiple groups
1 parent 62b9b28 commit 64929a5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pandas/_libs/groupby.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from libc.stdlib cimport malloc, free
1818

1919
from util cimport numeric, get_nat
2020
from algos cimport (swap, TIEBREAK_AVERAGE, TIEBREAK_MIN, TIEBREAK_MAX,
21-
TIEBREAK_FIRST, TIEBREAK_FIRST_DESCENDING, TIEBREAK_DENSE)
21+
TIEBREAK_FIRST, TIEBREAK_DENSE)
2222
from algos import take_2d_axis1_float64_float64, groupsort_indexer, tiebreakers
2323

2424
cdef int64_t iNaT = get_nat()
@@ -189,9 +189,9 @@ def group_rank_object(ndarray[float64_t, ndim=2] out,
189189
elif tiebreak == TIEBREAK_FIRST:
190190
for j in range(i - dups + 1, i + 1):
191191
if ascending:
192-
out[_as[j], 0] = j + 1
192+
out[_as[j], 0] = j + 1 - grp_start
193193
else:
194-
out[_as[j], 0] = 2 * i - j - dups + 2
194+
out[_as[j], 0] = 2 * i - j - dups + 2 - grp_start
195195
elif tiebreak == TIEBREAK_DENSE:
196196
for j in range(i - dups + 1, i + 1):
197197
out[_as[j], 0] = vals_seen

pandas/_libs/groupby_helper.pxi.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
520520
elif tiebreak == TIEBREAK_FIRST:
521521
for j in range(i - dups + 1, i + 1):
522522
if ascending:
523-
out[_as[j], 0] = j + 1
523+
out[_as[j], 0] = j + 1 - grp_start
524524
else:
525-
out[_as[j], 0] = 2 * i - j - dups + 2
525+
out[_as[j], 0] = 2 * i - j - dups + 2 - grp_start
526526
elif tiebreak == TIEBREAK_DENSE:
527527
for j in range(i - dups + 1, i + 1):
528528
out[_as[j], 0] = vals_seen

0 commit comments

Comments
 (0)