Repository navigation
[SPARK-60650][PS] Fix named size aggregation in pandas API on Spark - #59981
Open
adiranjan25 wants to merge 1 commit into
Open
adiranjan25 wants to merge 1 commit into
adiranjan25 wants to merge 1 commit into
Conversation
This branch has not been deployed
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 PR fixes named
sizeaggregation in the pandas API on Spark.Previously,
groupby().agg()with a namedsizeaggregation generated the Spark SQL expressionsize(column). Since Spark SQL'ssize()function expects an array or map, this caused a datatype mismatch for ordinary numeric columns.The fix translates named
sizeaggregation tocount(1), preserving pandas semantics by counting all rows, including rows with null values.Why are the changes needed?
In pandas,
GroupBy.size()counts all rows in each group, whereasGroupBy.count()excludes null values.Named aggregations should preserve this distinction.
Does this PR introduce any user-facing change?
Yes. Named
sizeaggregation now works correctly for ordinary columns in the pandas API on Spark.How was this patch tested?
Added
test_aggregate_relabel_size, comparing pandas and pandas-on-Spark results for namedsizeandcountaggregations on data containing null values.The regression test failed before the fix and passed afterward.
All three targeted aggregation tests passed locally. Ruff formatting and Git whitespace checks also passed.