Skip to content

Commit 33c5bfa

Browse files
authored
MAINT: stats.randint.pmf: fix zero PMF values within the support (scipy#21353)
* TST: stats.randint: add test for surprising underflow * MAINT: stats.randint.pmf: fix zero values within the support
1 parent 5fe2473 commit 33c5bfa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

scipy/stats/_discrete_distns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def _get_support(self, low, high):
12091209

12101210
def _pmf(self, k, low, high):
12111211
# randint.pmf(k) = 1./(high - low)
1212-
p = np.ones_like(k) / (high - low)
1212+
p = np.ones_like(k) / (np.asarray(high, dtype=np.int64) - low)
12131213
return np.where((k >= low) & (k < high), p, 0.)
12141214

12151215
def _cdf(self, x, low, high):

scipy/stats/tests/test_discrete_distns.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,15 @@ def test_gh20692(self):
646646
pmf = dist.pmf(k)
647647
pmf_k_int32 = dist.pmf(k_int32)
648648
assert_equal(pmf, pmf_k_int32)
649+
650+
651+
class TestRandInt:
652+
def test_gh19759(self):
653+
# test zero PMF values within the support reported by gh-19759
654+
a = -354
655+
max_range = abs(a)
656+
all_b_1 = [a + 2 ** 31 + i for i in range(max_range)]
657+
res = randint.pmf(325, a, all_b_1)
658+
assert (res > 0).all()
659+
ref = 1 / (np.asarray(all_b_1, dtype=np.float64) - a)
660+
assert_allclose(res, ref)

0 commit comments

Comments
 (0)