Repository navigation
[Python] Default MajorityVote tie_breaker to the configured normal_label - #41429
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR resolves #41232 by defaulting MajorityVote's tie_breaker parameter to None and resolving it to the configured normal_label after base class initialization, matching the documented behavior. The implementation is clean, backwards-compatible, and well-tested with unit tests covering both implicit and explicit tie-breakers with custom labels.
🔍 General Feedback
- Resolving
self._tie_breakertoself._normal_labelaftersuper().__init__(...)cleanly handles customnormal_labelvalues passed via**kwargswhile preserving default behavior whennormal_labelis omitted ortie_breakeris explicitly specified. - The unit tests in
aggregations_test.pyand theCHANGES.mdentry are clear and accurate.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @claudevdm 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). |
|
@shunping can you PTAL? |
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves #41232 by updating MajorityVote.__init__ so that tie_breaker defaults to None and resolves to self._normal_label after base class initialization, rather than hardcoding DEFAULT_NORMAL_LABEL. The fix is concise, preserves existing behavior when tie_breaker or default labels are used, and includes thorough unit test coverage and changelog updates.
🔍 General Feedback
- The implementation and unit tests in
aggregations.pyandaggregations_test.pyare well-structured, properly typed, and adhere to project conventions. - No issues found.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
tie_breaker defaulted to the constant DEFAULT_NORMAL_LABEL (0) instead of normal_label, so a tie with custom labels returned a label that is not one of the configured ones, or the outlier. It now defaults to None, resolved to normal_label.
faa53c8 to
ac82515
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41429 +/- ##
=========================================
Coverage 58.73% 58.73%
Complexity 2315 2315
=========================================
Files 1135 1135
Lines 170483 170504 +21
Branches 1499 1499
=========================================
+ Hits 100138 100151 +13
- Misses 67800 67806 +6
- Partials 2545 2547 +2
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:
|
Fixes #41232
MajorityVote.__init__defaultedtie_breakerto the constantDEFAULT_NORMAL_LABEL(0), although the docstring says it defaults tonormal_label. With custom labels a tie therefore returned a label that is not one of the configured labels (MajorityVote(normal_label=5, outlier_label=7).apply([AnomalyPrediction(label=5), AnomalyPrediction(label=7)])gavelabel=0) or, withnormal_label=1, outlier_label=0, the outlier.tie_breakernow defaults toNone, which is resolved tonormal_label; an explicittie_breakerbehaves as before and the default labels are unchanged.Tests:
test_tie_breaker_defaults_to_custom_normal_labelfails on master (label=0 != label=5) and passes with the change;test_explicit_tie_breaker_with_custom_labelspins the explicit case.pytest apache_beam/ml/anomaly/aggregations_test.py: 10 passed (1 failed on master);pytest apache_beam/ml/anomaly: 99 passed, 2 skipped. yapf and ruff are clean on the touched files. CHANGES.md updated.