Skip to content

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

Description

@lbaumbauer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions