Skip to content

Commit ad58b22

Browse files
authored
BUG: stats: adapt to np.floor type promotion removal (#21283)
* BUG: stats: adapt to `np.floor` type promotion removal `rv_discrete._cdf` relied on `np.floor` promoting its integer input to `np.float64`. This is no longer the case since numpy/numpy#26766.
1 parent 33c5bfa commit ad58b22

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

scipy/stats/_distn_infrastructure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3393,7 +3393,7 @@ def _cdf_single(self, k, *args):
33933393
return np.sum(self._pmf(m, *args), axis=0)
33943394

33953395
def _cdf(self, x, *args):
3396-
k = floor(x)
3396+
k = floor(x).astype(np.float64)
33973397
return self._cdfvec(k, *args)
33983398

33993399
# generic _logcdf, _sf, _logsf, _ppf, _isf, _rvs defined in rv_generic

scipy/stats/tests/test_discrete_basic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,15 @@ def test_rv_sample():
550550
rng = np.random.default_rng(98430143469)
551551
rvs0 = dist.ppf(rng.random(size=100))
552552
assert_allclose(rvs, rvs0)
553+
554+
def test__pmf_float_input():
555+
# gh-21272
556+
# test that `rvs()` can be computed when `_pmf` requires float input
557+
558+
class rv_exponential(stats.rv_discrete):
559+
def _pmf(self, i):
560+
return (2/3)*3**(1 - i)
561+
562+
rv = rv_exponential(a=0.0, b=float('inf'))
563+
rvs = rv.rvs(random_state=42) # should not crash due to integer input to `_pmf`
564+
assert_allclose(rvs, 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy