summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-03-20 21:58:42 -0400
committerCharles Harris <charlesr.harris@gmail.com>2015-03-20 21:58:42 -0400
commit59be9173bd909c4dc472b17d8c9f7f62cd11f8bd (patch)
treef33893728b2150b5d673e4708ca302beb04752e7 /numpy/lib/tests/test_function_base.py
parenta55c7fdfb45451b9b0334b68569548db42c3ac06 (diff)
parent594c64cedc3e521bc223fb90f29f22b034de3839 (diff)
downloadnumpy-59be9173bd909c4dc472b17d8c9f7f62cd11f8bd.tar.gz
Merge pull request #5683 from matthew-brett/deprecate-bias-ddof
BUG: deprecation for ignored corrcoef args
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index a37c527d9..cf9fcf5e2 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -8,8 +8,9 @@ from numpy.testing import (
run_module_suite, TestCase, assert_, assert_equal, assert_array_equal,
assert_almost_equal, assert_array_almost_equal, assert_raises,
assert_allclose, assert_array_max_ulp, assert_warns,
- assert_raises_regex, dec
+ assert_raises_regex, dec, clear_and_catch_warnings
)
+import numpy.lib.function_base as nfb
from numpy.random import rand
from numpy.lib import *
from numpy.compat import long
@@ -1305,6 +1306,12 @@ class TestCheckFinite(TestCase):
assert_(a.dtype == np.float64)
+class catch_warn_nfb(clear_and_catch_warnings):
+ """ Context manager to catch, reset warnings in function_base module
+ """
+ class_modules = (nfb,)
+
+
class TestCorrCoef(TestCase):
A = np.array(
[[0.15391142, 0.18045767, 0.14197213],
@@ -1335,8 +1342,26 @@ class TestCorrCoef(TestCase):
assert_almost_equal(corrcoef(self.A, self.B), self.res2)
def test_ddof(self):
- assert_almost_equal(corrcoef(self.A, ddof=-1), self.res1)
- assert_almost_equal(corrcoef(self.A, self.B, ddof=-1), self.res2)
+ # ddof raises DeprecationWarning
+ with catch_warn_nfb():
+ warnings.simplefilter("always")
+ assert_warns(DeprecationWarning, corrcoef, self.A, ddof=-1)
+ warnings.simplefilter("ignore")
+ # ddof has no or negligible effect on the function
+ assert_almost_equal(corrcoef(self.A, ddof=-1), self.res1)
+ assert_almost_equal(corrcoef(self.A, self.B, ddof=-1), self.res2)
+ assert_almost_equal(corrcoef(self.A, ddof=3), self.res1)
+ assert_almost_equal(corrcoef(self.A, self.B, ddof=3), self.res2)
+
+ def test_bias(self):
+ # bias raises DeprecationWarning
+ with catch_warn_nfb():
+ warnings.simplefilter("always")
+ assert_warns(DeprecationWarning, corrcoef, self.A, self.B, 1, 0)
+ assert_warns(DeprecationWarning, corrcoef, self.A, bias=0)
+ warnings.simplefilter("ignore")
+ # bias has no or negligible effect on the function
+ assert_almost_equal(corrcoef(self.A, bias=1), self.res1)
def test_complex(self):
x = np.array([[1, 2, 3], [1j, 2j, 3j]])
@@ -1356,13 +1381,6 @@ class TestCorrCoef(TestCase):
assert_array_equal(corrcoef(np.array([]).reshape(2, 0)),
np.array([[np.nan, np.nan], [np.nan, np.nan]]))
- def test_wrong_ddof(self):
- x = np.array([[0, 2], [1, 1], [2, 0]]).T
- with warnings.catch_warnings(record=True):
- warnings.simplefilter('always', RuntimeWarning)
- assert_array_equal(corrcoef(x, ddof=5),
- np.array([[np.nan, np.nan], [np.nan, np.nan]]))
-
class TestCov(TestCase):
def test_basic(self):