Skip to content

Commit

Permalink
Deprecate the None argument
Browse files Browse the repository at this point in the history
  • Loading branch information
tavinathanson committed May 1, 2016
1 parent 7c5d6a0 commit 70bbb67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions scipy/stats/stats.py
Expand Up @@ -4385,20 +4385,20 @@ def mannwhitneyu(x, y, use_continuity=True, alternative=None):
use_continuity : bool, optional
Whether a continuity correction (1/2.) should be taken into
account. Default is True.
alternative : None, 'less', 'two-sided', or 'greater'
alternative : None (deprecated), 'less', 'two-sided', or 'greater'
Whether to get the p-value for the one-sided hypothesis ('less'
or 'greater'), or for the two-sided hypothesis ('two-sided').
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 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.
the 'two-sided' p-value and a different U statistic. The
default behavior is not the same as using 'less' or 'greater':
it only exists for backward compatibility and is deprecated.
Returns
-------
statistic : float
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.
`alternative` is equal to None (deprecated; exists for backward
compatibility), 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 All @@ -4413,6 +4413,10 @@ def mannwhitneyu(x, y, use_continuity=True, alternative=None):
This test corrects for ties and by default uses a continuity correction.
"""
if alternative is None:
warnings.warn("Calling `mannwhitneyu` without specifying "
"`alternative` is deprecated.", DeprecationWarning)

x = np.asarray(x)
y = np.asarray(y)
n1 = len(x)
Expand Down
18 changes: 11 additions & 7 deletions scipy/stats/tests/test_stats.py
Expand Up @@ -2760,9 +2760,11 @@ def test_mannwhitneyu_two_sided(self):

def test_mannwhitneyu_default(self):
# The default value for alternative is None
u1, p1 = stats.mannwhitneyu(self.X, self.Y)
u2, p2 = stats.mannwhitneyu(self.Y, self.X)
u3, p3 = stats.mannwhitneyu(self.X, self.Y, alternative=None)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
u1, p1 = stats.mannwhitneyu(self.X, self.Y)
u2, p2 = stats.mannwhitneyu(self.Y, self.X)
u3, p3 = stats.mannwhitneyu(self.X, self.Y, alternative=None)

assert_equal(p1, p2)
assert_equal(p1, p3)
Expand Down Expand Up @@ -2806,10 +2808,12 @@ def test_mannwhitneyu_no_correct_two_sided(self):

def test_mannwhitneyu_no_correct_default(self):
# The default value for alternative is None
u1, p1 = stats.mannwhitneyu(self.X, self.Y, False)
u2, p2 = stats.mannwhitneyu(self.Y, self.X, False)
u3, p3 = stats.mannwhitneyu(self.X, self.Y, False,
alternative=None)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
u1, p1 = stats.mannwhitneyu(self.X, self.Y, False)
u2, p2 = stats.mannwhitneyu(self.Y, self.X, False)
u3, p3 = stats.mannwhitneyu(self.X, self.Y, False,
alternative=None)

assert_equal(p1, p2)
assert_equal(p1, p3)
Expand Down

0 comments on commit 70bbb67

Please sign in to comment.