Skip to content

Commit

Permalink
Merge pull request scipy#11180 from WarrenWeckesser/dupnormtest
Browse files Browse the repository at this point in the history
MAINT: stats: Some clean up in test_distributions.py.
  • Loading branch information
ev-br authored Dec 8, 2019
2 parents 5421b30 + 5523487 commit 1ada025
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions scipy/stats/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,6 @@ def test_mean_small_p(self):
assert_allclose(m, 1.000000005)


class TestNorm(object):
def test_bad_keyword_arg(self):
x = [1, 2, 3]
assert_raises(TypeError, stats.norm.fit, x, plate="shrimp")


class TestPareto(object):
def test_stats(self):
# Check the stats() method with some simple values. Also check
Expand Down Expand Up @@ -1277,10 +1271,22 @@ def test_moments_warnings(self):
warnings.simplefilter('error', RuntimeWarning)
stats.f.stats(dfn=[11]*4, dfd=[2, 4, 6, 8], moments='mvsk')

@pytest.mark.xfail(reason='f stats does not properly broadcast')
def test_stats_broadcast(self):
# stats do not fully broadcast just yet
mv = stats.f.stats(dfn=11, dfd=[11, 12])
dfn = np.array([[3], [11]])
dfd = np.array([11, 12])
m, v, s, k = stats.f.stats(dfn=dfn, dfd=dfd, moments='mvsk')
m2 = [dfd / (dfd - 2)]*2
assert_allclose(m, m2)
v2 = 2 * dfd**2 * (dfn + dfd - 2) / dfn / (dfd - 2)**2 / (dfd - 4)
assert_allclose(v, v2)
s2 = ((2*dfn + dfd - 2) * np.sqrt(8*(dfd - 4)) /
((dfd - 6) * np.sqrt(dfn*(dfn + dfd - 2))))
assert_allclose(s, s2)
k2num = 12 * (dfn * (5*dfd - 22) * (dfn + dfd - 2) +
(dfd - 4) * (dfd - 2)**2)
k2den = dfn * (dfd - 6) * (dfd - 8) * (dfn + dfd - 2)
k2 = k2num / k2den
assert_allclose(k, k2)


def test_rvgeneric_std():
Expand Down Expand Up @@ -1503,7 +1509,6 @@ def test_inf_raises_error(self):


class TestNorm(object):
"""gh-10300"""
def test_nan_raises_error(self):
# see gh-issue 10300
x = np.array([1.6483, 2.7169, 2.4667, 1.1791, 3.5433, np.nan])
Expand All @@ -1514,6 +1519,10 @@ def test_inf_raises_error(self):
x = np.array([1.6483, 2.7169, 2.4667, 1.1791, 3.5433, np.inf])
assert_raises(RuntimeError, stats.norm.fit, x)

def test_bad_keyword_arg(self):
x = [1, 2, 3]
assert_raises(TypeError, stats.norm.fit, x, plate="shrimp")


class TestUniform(object):
"""gh-10300"""
Expand Down Expand Up @@ -3112,7 +3121,7 @@ def test_540_567():
def test_regression_ticket_1316():
# The following was raising an exception, because _construct_default_doc()
# did not handle the default keyword extradoc=None. See ticket #1316.
g = stats._continuous_distns.gamma_gen(name='gamma')
stats._continuous_distns.gamma_gen(name='gamma')


def test_regression_ticket_1326():
Expand Down Expand Up @@ -3772,10 +3781,10 @@ def test_genextreme_give_no_warnings():
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

p = stats.genextreme.cdf(.5, 0)
p = stats.genextreme.pdf(.5, 0)
p = stats.genextreme.ppf(.5, 0)
p = stats.genextreme.logpdf(-np.inf, 0.0)
stats.genextreme.cdf(.5, 0)
stats.genextreme.pdf(.5, 0)
stats.genextreme.ppf(.5, 0)
stats.genextreme.logpdf(-np.inf, 0.0)
number_of_warnings_thrown = len(w)
assert_equal(number_of_warnings_thrown, 0)

Expand Down

0 comments on commit 1ada025

Please sign in to comment.