Skip to content

[Python] Add missing Histogram.p95 used by HistogramResult.p95 - #41710

Open
leninworld wants to merge 1 commit into
apache:masterfrom
leninworld:fix/41709-histogram-p95
Open

leninworld wants to merge 1 commit into
apache:masterfrom
leninworld:fix/41709-histogram-p95

Conversation

@leninworld

Copy link
Copy Markdown

Fixes #41709

HistogramResult.p95 calls self.data.histogram.p95(), but Histogram had no p95() method, so reading .p95 on a histogram metric result raised AttributeError. This adds Histogram.p95() next to p50()/p90()/p99(), using the same get_linear_interpolation call.

Testing

  • Added HistogramTest.test_p95 (apache_beam/utils/histogram_test.py) and TestHistogramCell.test_result_p95 (apache_beam/metrics/cells_test.py, the HistogramResult.p95 path). Both fail on master with AttributeError: 'Histogram' object has no attribute 'p95' and pass with the fix.
  • pytest apache_beam/metrics apache_beam/utils/histogram_test.py: 91 passed.
  • yapf --diff (0.43.0), ruff check (0.17.6) and whitespacelint are clean on the changed files.

HistogramResult.p95 called Histogram.p95(), which did not exist, so
reading .p95 on a histogram metric result raised AttributeError.

Fixes apache#41709
@github-actions github-actions Bot added python size/s S: 10-49 lines changed labels Nov 27, 2026

@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 adds the missing Histogram.p95() method in apache_beam/utils/histogram.py, fixing an AttributeError when accessing HistogramResult.p95. The implementation is clean, consistent with the existing percentile methods (p99, p90, p50), and includes appropriate unit tests for both Histogram and HistogramResult.

🔍 General Feedback

  • The fix directly resolves the broken HistogramResult.p95 property by delegating to self.get_linear_interpolation(0.95).
  • Unit test coverage in histogram_test.py and cells_test.py matches existing test conventions and verifies the end-to-end property access.

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

@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).

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]: [Python] HistogramResult.p95 raises AttributeError because Histogram has no p95()

1 participant