Repository navigation
[Python] Fix DataFrame idxmin and idxmax on empty or all-NA partitions - #41663
anishmehta24 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR fixes a ValueError in DeferredSeries and DeferredDataFrame idxmin()/idxmax() when an intermediate partition is empty (e.g., after filtering) or contains an all-NA/NaT column. By short-circuiting compute_idx when s.isna().all() or df.isna().all().any() is true, empty and all-NA partitions are safely forwarded to the final singleton aggregation stage.
🔍 General Feedback
- The fix in
sdks/python/apache_beam/dataframe/frames.pyis clean, concise, and preserves the existing fallback behavior forNAresults across bothskipna=Trueandskipna=False. - Unit tests in
frames_test.pyandtransforms_test.pythoroughly cover both all-NaTpartitions and empty partitions resulting from filter operations.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @damccorm 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 #41662
_idxmaxmin_helperruns pandasidxmax/idxminon every partition before the final step. pandas raisesValueErroron an empty partition (easy to get after a filter), and on an all-NA one for datetime, string and nullable dtypes, even when the whole column has values.compute_idxnow passes such a partition on unchanged, so the final step sees its rows and gives the pandas result. If every partition is empty, the final step still raises, as pandas does.Added
test_idxmin_idxmax_all_na_partitionto frames_test.py (each test partition holds one row there, so the NaT rows make all-NaT partitions) andtest_idxmin_idxmax_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.