Skip to content

Commit 6b39500

Browse files
committed
This commit removes remaining deprecated bias and ddof arguments from
`numpy.ma.extras` and updates the related tests. In addition: - Removed redundant declarations of `bias` and `ddof` in `extras.py` (deprecated since NumPy 2.0) - Removed associated tests from `test_extras.py` and `test_regression.py` - Amended `numpy/lib/_function_base_impl.py` to fully remove these arguments from function signatures and ensure consistency with documentation - Documented the above changes in the release notes All tests and Ruff checks pass locally.
1 parent 499530f commit 6b39500

5 files changed

Lines changed: 11 additions & 87 deletions

File tree

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
Removal of deprecated `trapz` function, `disp` method, and `bias`/`ddof` args in `corrcoef`
1+
Removal of deprecated `trapz` function, `disp` function, and `bias`/`ddof` args in `corrcoef`
22
-------------------------------------------------------------------------------------------
33

44
The following long-deprecated APIs have been removed:
55

66
* ``numpy.trapz`` — deprecated since NumPy 2.0 (2023-08-18). Use ``numpy.trapezoid`` or
77
``scipy.integrate`` functions instead.
8-
* ``disp`` method — deprecated in earlier releases and no longer functional. Use your own printing function instead.
8+
* ``disp`` function — deprecated from 2.0 release and no longer functional. Use your own printing function instead.
99
* ``bias`` and ``ddof`` arguments in ``numpy.corrcoef`` — these had no effect since NumPy 1.10.
1010

11-
Associated tests and type stubs have been updated or removed accordingly.
1211

numpy/lib/_function_base_impl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,13 +2869,13 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
28692869
return c.squeeze()
28702870

28712871

2872-
def _corrcoef_dispatcher(x, y=None, rowvar=None, bias=None, ddof=None, *,
2872+
def _corrcoef_dispatcher(x, y=None, rowvar=None,*,
28732873
dtype=None):
28742874
return (x, y)
28752875

28762876

28772877
@array_function_dispatch(_corrcoef_dispatcher)
2878-
def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
2878+
def corrcoef(x, y=None, rowvar=True, *,
28792879
dtype=None):
28802880
"""
28812881
Return Pearson product-moment correlation coefficients.

numpy/ma/extras.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ def cov(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None):
17291729
return result
17301730

17311731

1732-
def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, allow_masked=True,
1733-
ddof=np._NoValue):
1732+
def corrcoef(x, y=None, rowvar=True, allow_masked=True,
1733+
):
17341734
"""
17351735
Return Pearson product-moment correlation coefficients.
17361736
@@ -1751,6 +1751,11 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, allow_masked=True,
17511751
variable, with observations in the columns. Otherwise, the relationship
17521752
is transposed: each column represents a variable, while the rows
17531753
contain observations.
1754+
allow_masked : bool, optional
1755+
If True, masked values are propagated pair-wise: if a value is masked
1756+
in `x`, the corresponding value is masked in `y`.
1757+
If False, raises an exception. Because `bias` is deprecated, this
1758+
argument needs to be treated as keyword only to avoid a warning.
17541759
17551760
See Also
17561761
--------

numpy/ma/tests/test_extras.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,80 +1406,30 @@ def _create_data(self):
14061406
data2 = array(np.random.rand(12))
14071407
return data, data2
14081408

1409-
def test_ddof(self):
1410-
# ddof raises DeprecationWarning
1411-
x, y = self._create_data()
1412-
expected = np.corrcoef(x)
1413-
expected2 = np.corrcoef(x, y)
1414-
with pytest.warns(DeprecationWarning):
1415-
corrcoef(x, ddof=-1)
1416-
1417-
with warnings.catch_warnings():
1418-
warnings.filterwarnings(
1419-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1420-
1421-
# ddof has no or negligible effect on the function
1422-
assert_almost_equal(np.corrcoef(x, ddof=0), corrcoef(x, ddof=0))
1423-
assert_almost_equal(corrcoef(x, ddof=-1), expected)
1424-
assert_almost_equal(corrcoef(x, y, ddof=-1), expected2)
1425-
assert_almost_equal(corrcoef(x, ddof=3), expected)
1426-
assert_almost_equal(corrcoef(x, y, ddof=3), expected2)
1427-
1428-
def test_bias(self):
1429-
x, y = self._create_data()
1430-
expected = np.corrcoef(x)
1431-
# bias raises DeprecationWarning
1432-
with pytest.warns(DeprecationWarning):
1433-
corrcoef(x, y, True, False)
1434-
with pytest.warns(DeprecationWarning):
1435-
corrcoef(x, y, True, True)
1436-
with pytest.warns(DeprecationWarning):
1437-
corrcoef(x, y, bias=False)
14381409

1439-
with warnings.catch_warnings():
1440-
warnings.filterwarnings(
1441-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1442-
# bias has no or negligible effect on the function
1443-
assert_almost_equal(corrcoef(x, bias=1), expected)
14441410

14451411
def test_1d_without_missing(self):
14461412
# Test cov on 1D variable w/o missing values
14471413
x = self._create_data()[0]
14481414
assert_almost_equal(np.corrcoef(x), corrcoef(x))
14491415
assert_almost_equal(np.corrcoef(x, rowvar=False),
14501416
corrcoef(x, rowvar=False))
1451-
with warnings.catch_warnings():
1452-
warnings.filterwarnings(
1453-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1454-
assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True),
1455-
corrcoef(x, rowvar=False, bias=True))
14561417

14571418
def test_2d_without_missing(self):
14581419
# Test corrcoef on 1 2D variable w/o missing values
14591420
x = self._create_data()[0].reshape(3, 4)
14601421
assert_almost_equal(np.corrcoef(x), corrcoef(x))
14611422
assert_almost_equal(np.corrcoef(x, rowvar=False),
14621423
corrcoef(x, rowvar=False))
1463-
with warnings.catch_warnings():
1464-
warnings.filterwarnings(
1465-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1466-
assert_almost_equal(np.corrcoef(x, rowvar=False, bias=True),
1467-
corrcoef(x, rowvar=False, bias=True))
14681424

14691425
def test_1d_with_missing(self):
14701426
# Test corrcoef 1 1D variable w/missing values
14711427
x = self._create_data()[0]
14721428
x[-1] = masked
14731429
x -= x.mean()
14741430
nx = x.compressed()
1475-
assert_almost_equal(np.corrcoef(nx), corrcoef(x))
14761431
assert_almost_equal(np.corrcoef(nx, rowvar=False),
14771432
corrcoef(x, rowvar=False))
1478-
with warnings.catch_warnings():
1479-
warnings.filterwarnings(
1480-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1481-
assert_almost_equal(np.corrcoef(nx, rowvar=False, bias=True),
1482-
corrcoef(x, rowvar=False, bias=True))
14831433
try:
14841434
corrcoef(x, allow_masked=False)
14851435
except ValueError:
@@ -1489,14 +1439,6 @@ def test_1d_with_missing(self):
14891439
assert_almost_equal(np.corrcoef(nx, nx[::-1]), corrcoef(x, x[::-1]))
14901440
assert_almost_equal(np.corrcoef(nx, nx[::-1], rowvar=False),
14911441
corrcoef(x, x[::-1], rowvar=False))
1492-
with warnings.catch_warnings():
1493-
warnings.filterwarnings(
1494-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1495-
# ddof and bias have no or negligible effect on the function
1496-
assert_almost_equal(np.corrcoef(nx, nx[::-1]),
1497-
corrcoef(x, x[::-1], bias=1))
1498-
assert_almost_equal(np.corrcoef(nx, nx[::-1]),
1499-
corrcoef(x, x[::-1], ddof=2))
15001442

15011443
def test_2d_with_missing(self):
15021444
# Test corrcoef on 2D variable w/ missing value
@@ -1507,16 +1449,6 @@ def test_2d_with_missing(self):
15071449
test = corrcoef(x)
15081450
control = np.corrcoef(x)
15091451
assert_almost_equal(test[:-1, :-1], control[:-1, :-1])
1510-
with warnings.catch_warnings():
1511-
warnings.filterwarnings(
1512-
'ignore', "bias and ddof have no effect", DeprecationWarning)
1513-
# ddof and bias have no or negligible effect on the function
1514-
assert_almost_equal(corrcoef(x, ddof=-2)[:-1, :-1],
1515-
control[:-1, :-1])
1516-
assert_almost_equal(corrcoef(x, ddof=3)[:-1, :-1],
1517-
control[:-1, :-1])
1518-
assert_almost_equal(corrcoef(x, bias=1)[:-1, :-1],
1519-
control[:-1, :-1])
15201452

15211453

15221454
class TestPolynomial:

numpy/ma/tests/test_regression.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ def test_var_sets_maskedarray_scalar(self):
5959
a.var(out=mout)
6060
assert_(mout._data == 0)
6161

62-
def test_ddof_corrcoef(self):
63-
# See gh-3336
64-
x = np.ma.masked_equal([1, 2, 3, 4, 5], 4)
65-
y = np.array([2, 2.5, 3.1, 3, 5])
66-
# this test can be removed after deprecation.
67-
with warnings.catch_warnings():
68-
warnings.filterwarnings(
69-
'ignore', "bias and ddof have no effect", DeprecationWarning)
70-
r0 = np.ma.corrcoef(x, y, ddof=0)
71-
r1 = np.ma.corrcoef(x, y, ddof=1)
72-
# ddof should not have an effect (it gets cancelled out)
73-
assert_allclose(r0.data, r1.data)
7462

7563
def test_mask_not_backmangled(self):
7664
# See gh-10314. Test case taken from gh-3140.

0 commit comments

Comments
 (0)