Skip to content

[Python] Default MajorityVote tie_breaker to the configured normal_label - #41429

Merged
shunping merged 2 commits into
apache:masterfrom
sohailshk:fix/41232-majority-vote-tie-breaker
Nov 25, 2026
Merged

shunping merged 2 commits into
apache:masterfrom
sohailshk:fix/41232-majority-vote-tie-breaker

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

Fixes #41232

MajorityVote.__init__ defaulted tie_breaker to the constant DEFAULT_NORMAL_LABEL (0), although the docstring says it defaults to normal_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)]) gave label=0) or, with normal_label=1, outlier_label=0, the outlier. tie_breaker now defaults to None, which is resolved to normal_label; an explicit tie_breaker behaves as before and the default labels are unchanged.

Tests: test_tie_breaker_defaults_to_custom_normal_label fails on master (label=0 != label=5) and passes with the change; test_explicit_tie_breaker_with_custom_labels pins 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.

@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 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_breaker to self._normal_label after super().__init__(...) cleanly handles custom normal_label values passed via **kwargs while preserving default behavior when normal_label is omitted or tie_breaker is explicitly specified.
  • The unit tests in aggregations_test.py and the CHANGES.md entry are clear and accurate.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

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

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @claudevdm 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).

@claudevdm

Copy link
Copy Markdown
Collaborator

@shunping can you PTAL?

@claudevdm
claudevdm requested a review from shunping November 19, 2026 13:52
@claudevdm

Copy link
Copy Markdown
Collaborator

/gemini review

@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 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.py and aggregations_test.py are 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.
@sohailshk
sohailshk force-pushed the fix/41232-majority-vote-tie-breaker branch from faa53c8 to ac82515 Compare November 24, 2026 03:44
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.73%. Comparing base (5508f74) to head (ab41457).
⚠️ Report is 2 commits behind head on master.

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     
Flag Coverage Δ
python 80.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@shunping
shunping merged commit 4139cd4 into apache:master Nov 25, 2026
91 of 93 checks passed
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]: MajorityVote tie_breaker ignores a custom normal_label

3 participants