A robot vision team can use a review queue to inspect the highest-priority images from a test run. A simple rule such as "send all candidates with rank at most two" becomes ambiguous when two candidates tie at the cutoff. One export might list both images, while another lists neither. The scores can be identical in both exports.

Consider four candidate images with integer review scores of 94, 87, 87, and 71. A larger score means higher review priority. The two candidates that scored 87 occupy the second and third positions. If both receive the smaller of those positions, their rank is 2 and both enter the review queue under a rank-at-most-two policy. If both receive the average of their positions, their rank is 2.5 and neither enters the queue.

Decide whether the limit applies to ranks or rows

SciPy's rankdata starts at rank 1 and assigns smaller values earlier ranks. Negate a suitably typed score array if a higher score represents higher priority. In the example below, the scores are signed integers and the negation is within their representable range.

import numpy as np

from scipy.stats import rankdata

scores = np.array([94, 87, 87, 71], dtype=np.int64)

priority = -scores

expected = {

"min": [1, 2, 2, 4],

"average": [1, 2.5, 2.5, 4],

"dense": [1, 2, 2, 3],

"ordinal": [1, 2, 3, 4],

}

for method, ranks in expected.items():

np.testing.assert_array_equal(

rankdata(priority, method=method), ranks

)

order = [0, 2, 1, 3]

reordered = rankdata(priority[order], method="ordinal")

assert reordered[np.argsort(order)].tolist() == [1, 3, 2, 4]

A dense-rank cutoff admits a fixed number of distinct score levels. The third level above begins at rank 3 under dense ranking and rank 4 under competition ranking. Ordinal ranks assign distinct positions to equal scores according to input order. The fixture swaps the two tied candidates and shows that their ordinal positions swap as well. That input order can change when batches are combined.

If operators can review exactly two images, the queue needs an explicit secondary order for ties. A stable candidate ID can make the order reproducible when the candidates have equal priority. When review capacity can expand to cover a tied score group, record the tie policy and expect the number of rows to vary. Keep the candidate's original score and ID alongside its rank so a reviewer can see why it was selected.

Give missing scores their own status

A failed score calculation needs a different interpretation from a low score. SciPy's omit policy ranks the available scores and leaves a NaN at each missing location. Raise can be appropriate when the review batch requires every score to exist. The default propagate policy returns all NaN ranks when a NaN makes the ranks undefined along the ranked slice. Make the handling explicit before passing results to the queue.

If the same report also runs in SQL, check the peer definition. PostgreSQL's rank and dense_rank assign the same result to rows with the same ordering values, while row_number assigns each row a separate position. A candidate ID included in the window ordering can break the peer group, so use it only where the queue is intended to distinguish equal scores. The four-row fixture is small enough to compare directly between implementations.

Sources

SciPy rankdata reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rankdata.html

PostgreSQL window functions reference: https://www.postgresql.org/docs/current/functions-window.html