[SPARK-56219][PS][FOLLOW-UP] Keep legacy groupby idxmax and idxmin skipna=False behavior for pandas 2#55121
Open
ueshin wants to merge 2 commits intoapache:masterfrom
Open
[SPARK-56219][PS][FOLLOW-UP] Keep legacy groupby idxmax and idxmin skipna=False behavior for pandas 2#55121ueshin wants to merge 2 commits intoapache:masterfrom
ueshin wants to merge 2 commits intoapache:masterfrom
Conversation
Member
Author
zhengruifeng
approved these changes
Apr 1, 2026
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.
What changes were proposed in this pull request?
This is a follow-up of #55021.
This PR updates pandas-on-Spark
GroupBy.idxmaxandGroupBy.idxminforskipna=Falseto keep the legacy behavior for all pandas 2 versions.With this change:
< 3.0.0keeps the legacyidxmaxandidxminresult forskipna=False>= 3.0.0keeps the existing error behavior for NA-containing inputThis PR also updates the related test in
python/pyspark/pandas/tests/groupby/test_index.pyto validate the pandas 2 behavior directly instead of relying on pandas 2.2 and 2.3 having the same result.Why are the changes needed?
The previous fix split pandas 2.2 and pandas 2.3 behavior for
GroupBy.idxmax(skipna=False)andGroupBy.idxmin(skipna=False)on NA-containing input.For example:
In pandas 2.2, this returns:
In pandas 2.3, this returns:
In pandas 3, this raises
ValueError.Instead of matching the pandas 2.2 / 2.3 difference, this PR keeps the legacy pandas 2 behavior across all pandas 2 environments and continues to follow the pandas 3 behavior in pandas 3 environments.
Does this PR introduce any user-facing change?
Yes.
In pandas-on-Spark with pandas 2.x,
GroupBy.idxmax(skipna=False)andGroupBy.idxmin(skipna=False)on NA-containing groups now consistently keep the legacy result behavior instead of varying with the installed pandas 2 version.For pandas 3, behavior is unchanged from the current implementation.
How was this patch tested?
Ran the related pandas-on-Spark regression test in three environments:
GroupbyIndexTests.test_idxmax_idxmin_skipna_false_with_naGroupbyIndexTests.test_idxmax_idxmin_skipna_false_with_naGroupbyIndexTests.test_idxmax_idxmin_skipna_false_with_naWas this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)