@@ -514,30 +514,6 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
514
514
# Used to calculate tiebreakers
515
515
dups += 1
516
516
sum_ranks += i - grp_start + 1
517
- # if keep_na, check for missing values and assign back
518
- # to the result where appropriate
519
- if keep_na and mask[_as[i]]:
520
- grp_na_count += 1
521
- out[_as[i], 0] = nan
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
525
- if (i== N-1) or (labels[_as[i]] != labels[_as[i+1]]):
526
- grp_tie_count +=1
527
- if tiebreak != TIEBREAK_DENSE:
528
- for j in range(grp_start, i + 1):
529
- grp_sizes[_as[j], 0] = (i - grp_start + 1 -
530
- grp_na_count)
531
- else:
532
- for j in range(grp_start, i + 1):
533
- grp_sizes[_as[j], 0] = (grp_tie_count -
534
- (grp_na_count > 0))
535
- dups = sum_ranks = 0
536
- grp_na_count = 0
537
- grp_tie_count = 0
538
- grp_start = i + 1
539
- grp_vals_seen = 1
540
- continue
541
517
542
518
# Update out only when there is a transition of values or labels.
543
519
# When a new value or group is encountered, go back #dups steps(
@@ -548,7 +524,13 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
548
524
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or
549
525
(mask[_as[i]] ^ mask[_as[i+1]]) or
550
526
(labels[_as[i]] != labels[_as[i+1]])):
551
- if tiebreak == TIEBREAK_AVERAGE:
527
+ # if keep_na, check for missing values and assign back
528
+ # to the result where appropriate
529
+ if keep_na and mask[_as[i]]:
530
+ for j in range(i - dups + 1, i + 1):
531
+ out[_as[j], 0] = nan
532
+ grp_na_count = dups
533
+ elif tiebreak == TIEBREAK_AVERAGE:
552
534
for j in range(i - dups + 1, i + 1):
553
535
out[_as[j], 0] = sum_ranks / <float64_t>dups
554
536
elif tiebreak == TIEBREAK_MIN:
@@ -570,14 +552,14 @@ def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
570
552
# look forward to the next value (using the sorting in _as)
571
553
# if the value does not equal the current value then we need to
572
554
# reset the dups and sum_ranks, knowing that a new value is
573
- # coming up. the condition also needs to handle nan equality
555
+ # coming up. the conditional also needs to handle nan equality
574
556
# and the end of iteration
575
557
if (i == N - 1 or
576
558
(masked_vals[_as[i]] != masked_vals[_as[i+1]]) or
577
559
(mask[_as[i]] ^ mask[_as[i+1]])):
578
560
dups = sum_ranks = 0
579
561
grp_vals_seen += 1
580
- grp_tie_count +=1
562
+ grp_tie_count += 1
581
563
582
564
# Similar to the previous conditional, check now if we are
583
565
# moving to a new group. If so, keep track of the index where
0 commit comments