Skip to content

[Python] Fix DataFrame min and max on empty or all-NA partitions - #41733

Open
anishmehta24 wants to merge 1 commit into
apache:masterfrom
anishmehta24:fix/dataframe-min-max-na-partition
Open

anishmehta24 wants to merge 1 commit into
apache:masterfrom
anishmehta24:fix/dataframe-min-max-na-partition

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Fixes #41732

For min and max, DeferredSeries.aggregate wraps each partition's result in pd.Series(...). A partition with only missing values gives NaT or NA, and pd.Series makes that datetime64 or object, so the final step fails on timedelta, tz-aware datetime, string and nullable columns. An empty partition gives NaN, which turns a skipna=False result 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_partition to frames_test.py (each test partition holds one row there, so the NA rows make all-NA partitions) and test_min_max_skipna_false_with_empty_partition to 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.

@github-actions github-actions Bot added python size/s S: 10-49 lines changed labels Nov 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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-aware datetime64, nullable Int64, and string).
  • 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.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label python.
Backup reviewer: jrmccluskey (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DataFrame min() and max() fail or give NaN when a partition is empty or all-NA

1 participant