diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2015-03-15 11:34:58 -0700 |
---|---|---|
committer | Matthew Brett <matthew.brett@gmail.com> | 2015-03-15 11:45:18 -0700 |
commit | 594c64cedc3e521bc223fb90f29f22b034de3839 (patch) | |
tree | 3b1791109f3a70c0cc68855fe4f5bbe37477e831 /numpy/lib/tests/test_function_base.py | |
parent | 4b4d8510739c9ea7a80391e2656d84a3c5e4a9c3 (diff) | |
download | numpy-594c64cedc3e521bc223fb90f29f22b034de3839.tar.gz |
ENH: deprecate bias and ddof arguments to corrcoef
The bias and ddof arguments had no effect on the calculation of the
correlation coefficient because the value cancels in the calculation.
Deprecate these arguments to np.corrcoef and np.ma.corrcoef.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 38 |
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): |