Repository navigation
Conversation
|
/gemini review |
|
/gemini review |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41279 +/- ##
============================================
+ Coverage 57.48% 57.64% +0.15%
Complexity 2492 2492
============================================
Files 1204 1198 -6
Lines 171265 171357 +92
Branches 2103 2103
============================================
+ Hits 98456 98772 +316
+ Misses 70157 69933 -224
Partials 2652 2652
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly optimizes Index.partition_fn by replacing df.groupby(pids, sort=False) and speeds up DataFrameBatchConverter.explode_batch / SeriesBatchConverter by short-circuiting per-element null checks when not nulls.any() and constructing rows positionally via user_type._make / user_type(*values). The changes are well-benchmarked, preserve existing semantics, and have no correctness issues.
🔍 General Feedback
- In
Index.partition_fn, usingdict(tuple(df.groupby(pids, sort=False)))with an early return for empty frames avoids repeated full-frame scans and works across bothpd.DataFrameandpd.Seriesinputs. - In
DataFrameBatchConverter.explode_batchandSeriesBatchConverter, checkingif not nulls.any():before falling back to element-wisezip(nulls, series)and usingmap(user_type._make, zip(*iterators))forNamedTuplerow types eliminates per-row dictionary allocation and keyword-argument unpacking overhead.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
Full details of the methodology of generation and review can be found here - Apache Beam Python SDK Performance PRs Methodology & Branches Impact Ranking
If you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Summary of changes:
Optimizes
Index.partition_fn(dataframe/partitionings.py) andDataFrameBatchConverter.explode_batch/SeriesBatchConverter(typehints/pandas_type_compatibility.py):NamedTuple._makeinDataFrameBatchConverter.explode_batch:iter(series)directly whennot nulls.any()and constructs rows positionally viamap(user_type._make, zip(*iterators))instead of building and unpacking a{column: value}dict per row.df.groupby(pids, sort=False)inIndex.partition_fn:for key in range(num_partitions): yield key, df[hashes % num_partitions == key](which constructed a boolean mask and scanned the full DataFramedf.groupby(pids, sort=False).Dataflow benchmarks showing improvement:
2026-11-12_12_18_07-149332353087570228692026-11-12_12_18_08-17650989079603368963n1-standard-8,--autoscaling_algorithm=NONE --num_workers=1 --max_num_workers=1) Cloud Dataflow pipeline running30,000,000schemaPerfSchemaRowelements ·to_dataframe(pcoll)→ filter →to_pcollection(df), built-in transform stage execution time improved from556,120 ms->425,425 ms(1.31xfaster,-23.5%) (total single-worker job vCPU time:1578s->1740s).Additional benchmarks
upstream/mastervsupstream/master+ this PR alone):bench_50_dataframe_partition_and_explode(c2feb961eef) (on branchperf/py-benchmarks-suite) — 100 iterations ofIndex.partition_fn(df, 16)+DataFrameBatchConverter.explode_batch(df)on a 5,000-row DataFrame improved from736.27 ms->308.46 ms(2.39xfaster,-58.1%,-427.81 ms) in strict isolation.83.8%of savings,-322.90 ms):DataFrameBatchConverter.explode_batchusingiter(series)on non-null columns andmap(user_type._make, ...)—705.70 ms->382.80 ms(1.84xfaster,-45.8%).16.2%of savings,-62.58 ms, scales with partition count $P$): Single-passdf.groupby(pids, sort=False)inIndex.partition_fn(df, 16)—144.90 ms->82.32 ms(1.76xfaster,-43.2%).n2-standard-4Benchmark (p28_ms:28_dataframe_partition_explode_100x5k&suite3_parquet_dataframe): On a Cloud Dataflown2-standard-4worker, 100 iterations ofpartition_fn+explode_batchon 5,000-row DataFrames improved from1,261 ms->529 ms(2.38xfaster,-58.0%), andstage_df_partition_wall_msinsuite3_parquet_dataframeimproved from2,678 ms->2,210 ms(1.21xfaster).Testing
pytest sdks/python/apache_beam/dataframe/partitionings_test.py sdks/python/apache_beam/typehints/pandas_type_compatibility_test.py.