Skip to content

Commit 09238d3

Browse files
committed
update comments in groupby rank
1 parent fd1cb96 commit 09238d3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/_libs/groupby_helper.pxi.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
520520
grp_na_count += 1
521521
out[_as[i], 0] = nan
522522
grp_vals_seen = i + 1
523+
# when label transition happens, update grp_size to keep track
524+
# of number of nans encountered and increment grp_tie_count
523525
if (i== N-1) or (labels[_as[i]] != labels[_as[i+1]]):
524526
grp_tie_count +=1
525527
if tiebreak != TIEBREAK_DENSE:
@@ -537,6 +539,11 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
537539
grp_vals_seen = 1
538540
continue
539541

542+
# Update out only when there is a transition of values or labels.
543+
# When a new value or group is encountered, go back #dups steps(
544+
# the number of occurrence of current value) and assign the ranks
545+
# based on the the starting index of the current group (grp_start)
546+
# and the current index
540547
if (i == N - 1 or
541548
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or
542549
(mask[_as[i]] ^ mask[_as[i+1]]) or
@@ -563,7 +570,7 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
563570
# look forward to the next value (using the sorting in _as)
564571
# if the value does not equal the current value then we need to
565572
# reset the dups and sum_ranks, knowing that a new value is
566-
# coming up. the conditional also needs to handle nan equality
573+
# coming up. the condition also needs to handle nan equality
567574
# and the end of iteration
568575
if (i == N - 1 or
569576
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or

0 commit comments

Comments
 (0)