Skip to content

Commit

Permalink
MAINT: Avoid future error
Browse files Browse the repository at this point in the history
Ensure function output is scalar
  • Loading branch information
bashtage committed Jan 27, 2020
1 parent 6639bad commit 3f1b5e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions statsmodels/stats/libqsturng/qsturng_.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,20 +822,22 @@ def _psturng(q, r, v):
raise ValueError('q should be >= 0')

def opt_func(p, r, v):
return abs(_qsturng(p, r, v) - q)
return np.squeeze(abs(_qsturng(p, r, v) - q))

if v == 1:
if q < _qsturng(.9, r, 1):
return .1
elif q > _qsturng(.999, r, 1):
return .001
return 1. - fminbound(opt_func, .9, .999, args=(r,v))
soln = 1. - fminbound(opt_func, .9, .999, args=(r,v))
return np.atleast_1d(soln)
else:
if q < _qsturng(.1, r, v):
return .9
elif q > _qsturng(.999, r, v):
return .001
return 1. - fminbound(opt_func, .1, .999, args=(r,v))
soln = 1. - fminbound(opt_func, .1, .999, args=(r,v))
return np.atleast_1d(soln)

_vpsturng = np.vectorize(_psturng)
_vpsturng.__doc__ = """vector version of psturng"""
Expand Down
9 changes: 6 additions & 3 deletions statsmodels/stats/tests/test_pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,14 @@ def setup_class(cls):

def test_incorrect_output(self):
# too few groups
assert_raises(ValueError, MultiComparison, np.array([1] * 10), [1, 2] * 4)
with pytest.raises(ValueError):
MultiComparison(np.array([1] * 10), [1, 2] * 4)
# too many groups
assert_raises(ValueError, MultiComparison, np.array([1] * 10), [1, 2] * 6)
with pytest.raises(ValueError):
MultiComparison(np.array([1] * 10), [1, 2] * 6)
# just one group
assert_raises(ValueError, MultiComparison, np.array([1] * 10), [1] * 10)
with pytest.raises(ValueError):
MultiComparison(np.array([1] * 10), [1] * 10)

# group_order does not select all observations, only one group left
with warnings.catch_warnings(record=True) as w:
Expand Down

0 comments on commit 3f1b5e3

Please sign in to comment.