gh-154945: add regression test for NormalDist.quantiles(n < 1) - #155015
Closed
nikolauspschuetz wants to merge 1 commit into
Closed
gh-154945: add regression test for NormalDist.quantiles(n < 1)#155015nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
nikolauspschuetz
force-pushed
the
gh154945-normaldist-quantiles
branch
from
August 1, 2026 09:09
733ac96 to
a9051c2
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Adds test_quantiles_invalid_n to verify that NormalDist.quantiles(n) raises StatisticsError when n < 1, mirroring the module-level quantiles() validation. Currently fails (test is red) — quantiles(0) silently returns [] instead of raising.
nikolauspschuetz
force-pushed
the
gh154945-normaldist-quantiles
branch
from
August 1, 2026 09:11
a9051c2 to
9b48d46
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Member
|
We should just raise because statistics.quantile() raises already IIRC. |
Member
|
Also:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a regression test for the inconsistency reported in gh-154945:
NormalDist.quantiles(n)acceptsn < 1and silently returns[], whereas the module-levelstatistics.quantiles(data, n)rejects it withStatisticsError('n must be at least 1').NormalDist.quantilescomputes[self.inv_cdf(i / n) for i in range(1, n)]; withn=0the range is empty, so the invalid request produces an empty list instead of an error, and the two sibling APIs disagree.This PR is the failing test only, so CI shows it red against
main— that's the reproduction. It goes green with a two-line guard at the top ofNormalDist.quantiles, mirroring the module-level validation so both APIs behave identically:Notes on the choice:
quantiles()(Lib/statistics.py), so the two entry points raise identically — that consistency is the whole point of the report.n < 1is guarded.n == 1correctly returns[](one interval ⇒ zero cut points), matching the module-level function, so it is intentionally left unchanged.inv_cdfre-checksp <= 0 or p >= 1every loop iteration even thoughi / nis always in(0, 1). That's a separate micro-optimization and is deliberately not included here to keep this change to the reported correctness fix.@ayishaatwork — you asked to work on this on the issue; the guard above is the whole fix, so please feel free to send it as the source-side change and this test will turn green. I've verified both states locally on a built interpreter (
./python -m test test_statistics): the test fails onmainand passes with the guard, for both the pure-Python and the C-acceleratedNormalDist.