Skip to content

Commit

Permalink
Merge pull request scipy#13698 from WarrenWeckesser/arcsine-warnings
Browse files Browse the repository at this point in the history
BUG: stats: Fix spurious warnings generated by arcsine.pdf
  • Loading branch information
rgommers authored Mar 18, 2021
2 parents f575333 + c910acd commit 8726518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scipy/stats/_continuous_distns.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ class arcsine_gen(rv_continuous):
"""
def _pdf(self, x):
# arcsine.pdf(x) = 1/(pi*sqrt(x*(1-x)))
return 1.0/np.pi/np.sqrt(x*(1-x))
with np.errstate(divide='ignore'):
return 1.0/np.pi/np.sqrt(x*(1-x))

def _cdf(self, x):
return 2.0/np.pi*np.arcsin(np.sqrt(x))
Expand Down
12 changes: 11 additions & 1 deletion scipy/stats/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ def test_warns_p0(self):
assert_equal(stats.binom(n=2, p=0).std(), 0)


class TestArcsine:

def test_endpoints(self):
# Regression test for gh-13697. The following calculation
# should not generate a warning.
p = stats.arcsine.pdf([0, 1])
assert_equal(p, [np.inf, np.inf])


class TestBernoulli(object):
def setup_method(self):
np.random.seed(1234)
Expand Down Expand Up @@ -5435,7 +5444,7 @@ def test_fit(self, nu, loc, scale):

def dlogl_dnu(nu, loc, scale):
return ((-2*nu + 1) * np.sum(1/(samples - loc))
+ 2*nu/scale**2 * np.sum(samples - loc))
+ 2*nu/scale**2 * np.sum(samples - loc))

def dlogl_dloc(nu, loc, scale):
return (N * (1 + np.log(nu) - polygamma(0, nu)) +
Expand Down Expand Up @@ -5507,6 +5516,7 @@ def test_support_gh13294_regression(distname, args):
assert_equal(a, np.nan)
assert_equal(b, np.nan)


def test_support_broadcasting_gh13294_regression():
a0, b0 = stats.norm.support([0, 0, 0, 1], [1, 1, 1, -1])
ex_a0 = np.array([-np.inf, -np.inf, -np.inf, np.nan])
Expand Down

0 comments on commit 8726518

Please sign in to comment.