Repository navigation
[Python] Fix DataFrame min and max on empty or all-NA partitions - #41733
anishmehta24 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly fixes DeferredSeries.aggregate for min and max when encountering empty or all-NA partitions by preserving the input Series dtype in pre_aggregate and emitting an empty Series for empty partitions. The intermediate proxy is preserved via to_series(self._expr.proxy()) to avoid breaking existing proxy expectations, and unit tests in frames_test.py and transforms_test.py thoroughly cover the affected column types and skipna=False scenarios.
🔍 General Feedback
- The fix is well-targeted and properly handles both scalar (
func='min') and single-element Series (func=['min']) aggregation outputs while maintaining compatibility across Pandas dtypes (timedelta64, tz-awaredatetime64, nullableInt64, andstring). - Test coverage is comprehensive and directly exercises both all-NA partitions and empty partitions resulting from filtering.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #41732
For
minandmax,DeferredSeries.aggregatewraps each partition's result inpd.Series(...). A partition with only missing values givesNaTorNA, andpd.Seriesmakes that datetime64 or object, so the final step fails on timedelta, tz-aware datetime,stringand nullable columns. An empty partition gives NaN, which turns askipna=Falseresult into NaN. The per-partition step now keeps the input dtype and passes nothing on for an empty partition. Other aggregations are unchanged, and the intermediate keeps its old proxy, so the result proxies are the same as before.Added
test_min_max_all_na_partitionto frames_test.py (each test partition holds one row there, so the NA rows make all-NA partitions) andtest_min_max_skipna_false_with_empty_partitionto transforms_test.py (a pipeline where the filter leaves one batch empty). Both fail on master. The apache_beam/dataframe tests and the DataFrame and Series pandas doctests pass.