Polars argmax ties: the maximum can be correct while the selected row is wrong
A positional tie-breaking contract exposes selection errors that a value-only check cannot detect.
Some tasks care who owns the maximum
A correct maximum does not establish the correct selected row. Make tie-breaking part of the result-identity contract. When choosing a highest-scoring applicant or an event owner, returning the same number is insufficient evidence that the intended row was selected. [1, 2, 3]
The final tied position in a sorted path
Polars issue 30582 reports sorted arg_max and arg_min paths selecting the final tied position instead of the first occurrence. It contrasts sorted flags and grouped aggregation. Examine whether the returned position matches the approved tie semantics, not only the magnitude of the extreme. [1]
Fix the position basis before transformation
Preserve values with original row positions and compare tie controls against an explicit first-occurrence policy. Hold rollout if sortedness changes the owner. If another ordering is allowed, retain the mapping between original and current positions so the ordering defining first occurrence is clear. [1, 3]
Positions 1 and 2 can own the same maximum
For illustrative values [1,2,2] under a first-occurrence policy, the expected 0-based position is 1. Selecting position 1 preserves ownership by the first maximum row. Selecting position 2 transfers ownership to a later row carrying the same value. Both positions contain value 2, so a range check sees no difference. A last-occurrence business policy would require another expectation; do not impose this example's first-occurrence rule on it. [1, 3]
The Truthound comparison boundary
Truthound Core's ColumnPairValidator can compare prepared observed and expected positions. Check position completeness first and align both sides to the same original ordering. It does not replace argmax implementation. Test alternative selection with explicit tie keys and original positions against the same input before adopting it. [1, 2, 3]
Application conditions
Prepare maximum_value, selected_position and first_maximum_position from the same original ordering, independently approving the first-occurrence tie policy.
Alternatives
Compute selection with explicit tie-break keys and original row positions.
Limitations
A maximum-value range check cannot detect a wrong tie owner. Truthound does not replace argmax implementation.
Evidence
- Event checked
- Subject checked
- Modified
