Skip to content

BUG: DataFrame.idxmax wrong row for nullable boolean with NA - #71833

Open
jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:regr-66250
Open

jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:regr-66250

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

DataFrame.idxmax on a nullable boolean column with missing values returned the first False row instead of the first True row:

df = pd.DataFrame({"a": pd.array([False, pd.NA, True], dtype="boolean")})
df.idxmax()  # [0], Series.idxmax gives 2

nanops._get_fill_value gave bool the -inf fill, which np.putmask casts to True. The masked slot then beat any real True under argmax, and the redirect added in GH-66250 turned that into the first unmasked row; before GH-66250 the NA row's label came back. Bool now gets False/True fill values. idxmin was already right.

AI disclosure: drafted with Claude Code (claude opus 5.5 (high)), which found the bug in an audit of GH-66250, wrote the fix and tests, and ran a differential sweep against main.

@jbrockmendel jbrockmendel added Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc. labels Nov 1, 2026
jbrockmendel and others added 2 commits November 2, 2026 09:17
nanops._get_fill_value gave bool the +/-inf fill, which np.putmask casts
to True, so a masked slot outranked a real True under argmax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jbrockmendel
jbrockmendel marked this pull request as ready for review November 2, 2026 21:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant