Skip to content

Commit

Permalink
Make None fully backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tavinathanson committed Apr 28, 2016
1 parent 2be239a commit 7c5d6a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions scipy/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4389,14 +4389,16 @@ def mannwhitneyu(x, y, use_continuity=True, alternative=None):
Whether to get the p-value for the one-sided hypothesis ('less'
or 'greater'), or for the two-sided hypothesis ('two-sided').
Defaults to None, which results in a p-value half the size of
the 'two-sided' p-value. The default behavior is not the same
as using 'less' or 'greater', is not recommended, and will soon
be deprecated.
the 'two-sided' p-value and a different U statistic. The default
behavior is not the same as using 'less' or 'greater', is not
recommended, and will soon be deprecated.
Returns
-------
statistic : float
The Mann-Whitney statistics.
The Mann-Whitney U statistic, equal to min(U for x, U for y) if
`alternative` is equal to None (not recommended; to be deprecated),
and U for y otherwise.
pvalue : float
p-value assuming an asymptotic normal distribution. One-sided or
two-sided, depending on the choice of `alternative`.
Expand Down Expand Up @@ -4437,15 +4439,19 @@ def mannwhitneyu(x, y, use_continuity=True, alternative=None):

z = (bigu - meanrank) / sd
if alternative is None:
# This behavior, equal to one-half the size of the two-sided
# This behavior, equal to half the size of the two-sided
# p-value, will soon be deprecated.
p = distributions.norm.sf(abs(z))
elif alternative == 'two-sided':
p = 2 * distributions.norm.sf(abs(z))
else:
p = distributions.norm.sf(z)

return MannwhitneyuResult(u2, p)
u = u2
# This behavior will soon be deprecated.
if alternative is None:
u = min(u1, u2)
return MannwhitneyuResult(u, p)

RanksumsResult = namedtuple('RanksumsResult', ('statistic', 'pvalue'))

Expand Down
8 changes: 4 additions & 4 deletions scipy/stats/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,9 +2766,9 @@ def test_mannwhitneyu_default(self):

assert_equal(p1, p2)
assert_equal(p1, p3)
assert_equal(u1, 498)
assert_equal(u1, 102)
assert_equal(u2, 102)
assert_equal(u3, 498)
assert_equal(u3, 102)
assert_approx_equal(p1, 4.5941632666275e-05,
significant=self.significant)

Expand Down Expand Up @@ -2813,9 +2813,9 @@ def test_mannwhitneyu_no_correct_default(self):

assert_equal(p1, p2)
assert_equal(p1, p3)
assert_equal(u1, 498)
assert_equal(u1, 102)
assert_equal(u2, 102)
assert_equal(u3, 498)
assert_equal(u3, 102)
assert_approx_equal(p1, 4.40940099958089e-05,
significant=self.significant)

Expand Down

0 comments on commit 7c5d6a0

Please sign in to comment.