@@ -520,6 +520,8 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
520
520
grp_na_count += 1
521
521
out[_as[i], 0] = nan
522
522
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
523
525
if (i== N-1) or (labels[_as[i]] != labels[_as[i+1]]):
524
526
grp_tie_count +=1
525
527
if tiebreak != TIEBREAK_DENSE:
@@ -537,6 +539,11 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
537
539
grp_vals_seen = 1
538
540
continue
539
541
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
540
547
if (i == N - 1 or
541
548
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or
542
549
(mask[_as[i]] ^ mask[_as[i+1]]) or
@@ -563,7 +570,7 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
563
570
# look forward to the next value (using the sorting in _as)
564
571
# if the value does not equal the current value then we need to
565
572
# 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
567
574
# and the end of iteration
568
575
if (i == N - 1 or
569
576
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or
0 commit comments