python / python/cpython

statistics module NormalDist.quantiles(0) should raise statistics error instead of returning empty list and makes redundant checks

Open
#154,945 4 comments 0 reactions 1 assignee View on GitHub

@rhettinger is already working on this.

Since Aug 6, 2026.

pending stdlib
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
import statistics

d = statistics.NormalDist()

print(d.quantiles(0))

output:
[]
  1. The called function inv_cdf checks for p <= 0 or .. during every iteration of the loop rather than once, even though all values of p are guaranteed to be in the range through the way they are generated as i / n.
self.inv_cdf(i / n) for i in range(1, n)

inv_cdf(self, p)
...
 if p <= 0.0 or p >= 1.0

It makes more sense to call the implementation _normal_dist_inv_cdf(p, self._mu, self._sigma) directly.

CPython versions tested on:

3.13

Operating systems tested on:

Other

Linked PRs
  • gh-155015

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.