Fix GroupBy snippet tests for issue #30778#37672
Fix GroupBy snippet tests for issue #30778#37672MansiSingh17 wants to merge 1 commit intoapache:masterfrom
Conversation
- Add missing strawberry entry to GROCERY_LIST in all snippet files - Fix test() block scoping (moved inside with beam.Pipeline() context) - Remove beam.Map(print) from pipeline, add to else branch for standalone use - Fix check_simple_aggregate_result to compare Row objects directly - Set skip_due_to_30778 = False now that tests are passing - Restore [START]/[END] snippet markers and 2-space indentation
Summary of ChangesHello @MansiSingh17, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves several issues within the Apache Beam Python GroupBy snippet examples, which previously caused tests to be skipped or fail. By addressing data inconsistencies, correcting pipeline structure, and refining test helper logic, the changes ensure the correctness and reliability of these aggregation examples. The primary impact is the successful re-enablement and passing of all GroupBy snippet tests, improving the overall quality and trustworthiness of the example code. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
@hjtran The PreCommit Python Lint failure is pre-existing and not related to this PR. The E265/E501/E111 errors exist across the entire aggregation snippets directory and are present on master as well. Running git diff confirms none of the failing lint rules were introduced by this PR's changes. |
|
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). |
Hi @MansiSingh17! Great work identifying and fixing the root causes. Your approach is correct. I was also working on this issue and reviewed your PR carefully. I noticed a few things that might need attention:
if test:
test(grouped)
else:
grouped | beam.Map(print)
Happy to help address any of these if useful! Great effort overall on tackling this. |
|
Hi @mtauha, thanks for the detailed review! I've addressed all 4 points:
|
|
@mtauha The PreCommit Python Formatter failure is not related to my changes. Running yapf --diff locally on all changed files shows no formatting issues. This is a pre-existing failure on master. |
Fix GroupBy snippet tests and re-enable skipped assertions (fixes #30778)
The GroupBy snippet tests in groupby_test.py were permanently skipped via skip_due_to_30778 = True. This PR fixes the underlying issues in the snippet files so all 7 tests pass.
Root causes fixed:
Missing strawberry entry in GROCERY_LIST across all snippet files caused incorrect aggregate results
if test block was outside the with beam.Pipeline() context, making grouped inaccessible
beam.Map(print) was chained inside the pipeline, polluting the snippet and breaking test assertions
check_simple_aggregate_result was applying beam.MapTuple(normalize_kv) to Row objects returned by aggregate_field, which expects KV pairs
Files changed:
groupby_attr.py
groupby_attr_expr.py
groupby_expr.py
groupby_expr_aggregate.py
groupby_global_aggregate.py
groupby_simple_aggregate.py
groupby_two_exprs.py
groupby_test.py
Testing:
pytest -q sdks/python/apache_beam/examples/snippets/transforms/aggregation/groupby_test.py
7 passed in 0.99s
addresses #30778
Update CHANGES.md with noteworthy changes.