python / python/cpython

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

Đang mở
#154,945 4 bình luận 0 reaction 1 người được giao Xem trên GitHub

@rhettinger đang làm issue này rồi.

Từ ngày 6/8/2026.

pending stdlib
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.