BUG: idxmin/idxmax with skipna=False returned wrong results (GH-56903)#65910
Draft
jbrockmendel wants to merge 2 commits into
Draft
BUG: idxmin/idxmax with skipna=False returned wrong results (GH-56903)#65910jbrockmendel wants to merge 2 commits into
jbrockmendel wants to merge 2 commits into
Conversation
group_idxmin_idxmax initializes its output to the -1 all-NA sentinel and, with skipna=False, could not distinguish that initial state from a group that had actually encountered an NA. It therefore skipped every group and returned the sentinel for all of them. Gate the lock on `seen` so the sentinel only short-circuits once a real NA has been seen. This fixes DataFrame.idxmax/idxmin(axis=1, skipna=False) on extension-array dtypes and groupby idxmax/idxmin(skipna=False) on inputs with no NA values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Splits the bug fix out of GH-65597 (which becomes a pure performance PR).
group_idxmin_idxmaxinitializes its output to the-1all-NA sentinel, and withskipna=Falsethe guard that locks a group to NA could not tell that initial sentinel apart from a group that had genuinely encountered an NA — so it skipped every group and returned the sentinel for all of them. The fix gates the lock onseen[lab, j], which is only set once a group has been visited.Two user-visible bugs, both fixed by the one kernel change:
DataFrame.idxmax/DataFrame.idxminwithaxis=1andskipna=Falseon extension-array dtypes (e.g.BooleanDtype, nullable integer/float,ArrowDtype) returned incorrect column labels — the PERF: pd.BooleanDtype in row operations is still very slow #56903 manifestation.DataFrameGroupBy.idxmax/idxmin(andSeriesvariants) withskipna=Falsereturned incorrect results when the input had no NA values (the groupby wrapper raises whenever any NA is present, so the broken kernel path was only reached on all-non-NA input).GH-65597 still needs its own
skipna=Falseraise guard (the direct_groupby_opcall bypasses the groupby-level raise) but can drop theskipna = Trueworkaround once this lands.Test plan
pandas/tests/frame/test_reductions.py(axis=1 EA correctness vs numpy + all-NA-row raising)pandas/tests/groupby/test_reductions.py(skipna=Falsewith no NA values)pandas/tests/groupby,pandas/tests/arrays/masked,pandas/tests/extension— no regressionspre-commit runon changed files🤖 Generated with Claude Code