Skip to content

Commit a3c55b6

Browse files
authored
Merge pull request #29997 from Abhi210/gh-11521-remove-deprecations
MAINT: remove deprecated in numpy/lib/_function_base_impl.py
2 parents fcc3b6e + f1e088d commit a3c55b6

13 files changed

Lines changed: 18 additions & 244 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Removal of deprecated functions and arguments
2+
---------------------------------------------
3+
4+
The following long-deprecated APIs have been removed:
5+
6+
* ``numpy.trapz`` — deprecated since NumPy 2.0 (2023-08-18). Use ``numpy.trapezoid`` or
7+
``scipy.integrate`` functions instead.
8+
* ``disp`` function — deprecated from 2.0 release and no longer functional. Use your own printing function instead.
9+
* ``bias`` and ``ddof`` arguments in ``numpy.corrcoef`` — these had no effect since NumPy 1.10.

numpy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@
505505
sinc,
506506
sort_complex,
507507
trapezoid,
508-
trapz,
509508
trim_zeros,
510509
unwrap,
511510
vectorize,

numpy/__init__.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ from numpy.lib._function_base_impl import ( # type: ignore[deprecated]
460460
blackman,
461461
kaiser,
462462
trapezoid,
463-
trapz,
464463
i0,
465464
meshgrid,
466465
delete,
@@ -686,7 +685,7 @@ __all__ = [ # noqa: RUF022
686685
"gradient", "angle", "unwrap", "sort_complex", "flip", "rot90", "extract", "place",
687686
"vectorize", "asarray_chkfinite", "average", "bincount", "digitize", "cov",
688687
"corrcoef", "median", "sinc", "hamming", "hanning", "bartlett", "blackman",
689-
"kaiser", "trapezoid", "trapz", "i0", "meshgrid", "delete", "insert", "append",
688+
"kaiser", "trapezoid", "i0", "meshgrid", "delete", "insert", "append",
690689
"interp", "quantile",
691690
# lib._twodim_base_impl.__all__
692691
"diag", "diagflat", "eye", "fliplr", "flipud", "tri", "triu", "tril", "vander",

numpy/_core/tests/test_deprecations.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,8 @@ def test_deprecated_np_lib_math(self):
280280
class TestLibImports(_DeprecationTestCase):
281281
# Deprecated in Numpy 1.26.0, 2023-09
282282
def test_lib_functions_deprecation_call(self):
283-
from numpy import row_stack, trapz
283+
from numpy import row_stack
284284
from numpy._core.numerictypes import maximum_sctype
285-
from numpy.lib._function_base_impl import disp
286285
from numpy.lib._npyio_impl import recfromcsv, recfromtxt
287286
from numpy.lib._shape_base_impl import get_array_wrap
288287
from numpy.lib._utils_impl import safe_eval
@@ -295,12 +294,10 @@ def test_lib_functions_deprecation_call(self):
295294
self.assert_deprecated(lambda: recfromcsv(data_gen()))
296295
self.assert_deprecated(lambda: recfromtxt(data_gen(), **kwargs))
297296

298-
self.assert_deprecated(lambda: disp("test"))
299297
self.assert_deprecated(get_array_wrap)
300298
self.assert_deprecated(lambda: maximum_sctype(int))
301299

302300
self.assert_deprecated(lambda: row_stack([[]]))
303-
self.assert_deprecated(lambda: trapz([1], [1]))
304301
self.assert_deprecated(lambda: np.chararray)
305302

306303

numpy/_expired_attrs_2_0.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"or use `typing.deprecated`.",
6262
"deprecate_with_doc": "Emit `DeprecationWarning` with `warnings.warn` "
6363
"directly, or use `typing.deprecated`.",
64-
"disp": "Use your own printing function instead.",
6564
"find_common_type":
6665
"Use `numpy.promote_types` or `numpy.result_type` instead. "
6766
"To achieve semantics for the `scalar_types` argument, use "

numpy/_expired_attrs_2_0.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class _ExpiredAttributesType(TypedDict):
4747
recfromtxt: str
4848
deprecate: str
4949
deprecate_with_doc: str
50-
disp: str
5150
find_common_type: str
5251
round_: str
5352
get_array_wrap: str

numpy/lib/_function_base_impl.py

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import collections.abc
33
import functools
44
import re
5-
import sys
65
import warnings
76

87
import numpy as np
@@ -68,7 +67,7 @@
6867
'rot90', 'extract', 'place', 'vectorize', 'asarray_chkfinite', 'average',
6968
'bincount', 'digitize', 'cov', 'corrcoef',
7069
'median', 'sinc', 'hamming', 'hanning', 'bartlett',
71-
'blackman', 'kaiser', 'trapezoid', 'trapz', 'i0',
70+
'blackman', 'kaiser', 'trapezoid', 'i0',
7271
'meshgrid', 'delete', 'insert', 'append', 'interp',
7372
'quantile'
7473
]
@@ -2119,62 +2118,6 @@ def place(arr, mask, vals):
21192118
return _place(arr, mask, vals)
21202119

21212120

2122-
def disp(mesg, device=None, linefeed=True):
2123-
"""
2124-
Display a message on a device.
2125-
2126-
.. deprecated:: 2.0
2127-
Use your own printing function instead.
2128-
2129-
Parameters
2130-
----------
2131-
mesg : str
2132-
Message to display.
2133-
device : object
2134-
Device to write message. If None, defaults to ``sys.stdout`` which is
2135-
very similar to ``print``. `device` needs to have ``write()`` and
2136-
``flush()`` methods.
2137-
linefeed : bool, optional
2138-
Option whether to print a line feed or not. Defaults to True.
2139-
2140-
Raises
2141-
------
2142-
AttributeError
2143-
If `device` does not have a ``write()`` or ``flush()`` method.
2144-
2145-
Examples
2146-
--------
2147-
>>> import numpy as np
2148-
2149-
Besides ``sys.stdout``, a file-like object can also be used as it has
2150-
both required methods:
2151-
2152-
>>> from io import StringIO
2153-
>>> buf = StringIO()
2154-
>>> np.disp('"Display" in a file', device=buf)
2155-
>>> buf.getvalue()
2156-
'"Display" in a file\\n'
2157-
2158-
"""
2159-
2160-
# Deprecated in NumPy 2.0, 2023-07-11
2161-
warnings.warn(
2162-
"`disp` is deprecated, "
2163-
"use your own printing function instead. "
2164-
"(deprecated in NumPy 2.0)",
2165-
DeprecationWarning,
2166-
stacklevel=2
2167-
)
2168-
2169-
if device is None:
2170-
device = sys.stdout
2171-
if linefeed:
2172-
device.write(f'{mesg}\n')
2173-
else:
2174-
device.write(f'{mesg}')
2175-
device.flush()
2176-
2177-
21782121
# See https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
21792122
_DIMENSION_NAME = r'\w+'
21802123
_CORE_DIMENSION_LIST = f'(?:{_DIMENSION_NAME}(?:,{_DIMENSION_NAME})*)?'
@@ -2926,13 +2869,13 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
29262869
return c.squeeze()
29272870

29282871

2929-
def _corrcoef_dispatcher(x, y=None, rowvar=None, bias=None, ddof=None, *,
2872+
def _corrcoef_dispatcher(x, y=None, rowvar=None, *,
29302873
dtype=None):
29312874
return (x, y)
29322875

29332876

29342877
@array_function_dispatch(_corrcoef_dispatcher)
2935-
def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
2878+
def corrcoef(x, y=None, rowvar=True, *,
29362879
dtype=None):
29372880
"""
29382881
Return Pearson product-moment correlation coefficients.
@@ -2959,14 +2902,7 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
29592902
variable, with observations in the columns. Otherwise, the relationship
29602903
is transposed: each column represents a variable, while the rows
29612904
contain observations.
2962-
bias : _NoValue, optional
2963-
Has no effect, do not use.
29642905
2965-
.. deprecated:: 1.10.0
2966-
ddof : _NoValue, optional
2967-
Has no effect, do not use.
2968-
2969-
.. deprecated:: 1.10.0
29702906
dtype : data-type, optional
29712907
Data-type of the result. By default, the return data-type will have
29722908
at least `numpy.float64` precision.
@@ -2990,11 +2926,6 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
29902926
interval [-1, 1] in an attempt to improve on that situation but is not
29912927
much help in the complex case.
29922928
2993-
This function accepts but discards arguments `bias` and `ddof`. This is
2994-
for backwards compatibility with previous versions of this function. These
2995-
arguments had no effect on the return values of the function and can be
2996-
safely ignored in this and previous versions of numpy.
2997-
29982929
Examples
29992930
--------
30002931
>>> import numpy as np
@@ -3061,10 +2992,6 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
30612992
1. ]])
30622993
30632994
"""
3064-
if bias is not np._NoValue or ddof is not np._NoValue:
3065-
# 2015-03-15, 1.10
3066-
warnings.warn('bias and ddof have no effect and are deprecated',
3067-
DeprecationWarning, stacklevel=2)
30682995
c = cov(x, y, rowvar, dtype=dtype)
30692996
try:
30702997
d = diag(c)
@@ -5080,24 +5007,6 @@ def trapezoid(y, x=None, dx=1.0, axis=-1):
50805007
return ret
50815008

50825009

5083-
@set_module('numpy')
5084-
def trapz(y, x=None, dx=1.0, axis=-1):
5085-
"""
5086-
`trapz` is deprecated in NumPy 2.0.
5087-
5088-
Please use `trapezoid` instead, or one of the numerical integration
5089-
functions in `scipy.integrate`.
5090-
"""
5091-
# Deprecated in NumPy 2.0, 2023-08-18
5092-
warnings.warn(
5093-
"`trapz` is deprecated. Use `trapezoid` instead, or one of the "
5094-
"numerical integration functions in `scipy.integrate`.",
5095-
DeprecationWarning,
5096-
stacklevel=2
5097-
)
5098-
return trapezoid(y, x=x, dx=dx, axis=axis)
5099-
5100-
51015010
def _meshgrid_dispatcher(*xi, copy=None, sparse=None, indexing=None):
51025011
return xi
51035012

numpy/lib/_function_base_impl.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from typing import (
1414
overload,
1515
type_check_only,
1616
)
17-
from typing_extensions import TypeIs, deprecated
17+
from typing_extensions import TypeIs
1818

1919
import numpy as np
2020
from numpy import (
@@ -87,7 +87,6 @@ __all__ = [
8787
"blackman",
8888
"kaiser",
8989
"trapezoid",
90-
"trapz",
9190
"i0",
9291
"meshgrid",
9392
"delete",
@@ -990,10 +989,6 @@ def trapezoid(
990989
floating | complexfloating | timedelta64
991990
| NDArray[floating | complexfloating | timedelta64 | object_]
992991
): ...
993-
994-
@deprecated("Use 'trapezoid' instead")
995-
def trapz(y: ArrayLike, x: ArrayLike | None = None, dx: float = 1.0, axis: int = -1) -> generic | NDArray[generic]: ...
996-
997992
@overload
998993
def meshgrid(
999994
*,

numpy/lib/tests/test_function_base.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,6 @@ def test_return_dtype(self):
565565
m = np.isnan(d)
566566
assert_equal(select([m], [d]), [0, 0, 0, np.nan, 0, 0])
567567

568-
def test_deprecated_empty(self):
569-
assert_raises(ValueError, select, [], [], 3j)
570-
assert_raises(ValueError, select, [], [])
571-
572568
def test_non_bool_deprecation(self):
573569
choices = self.choices
574570
conditions = self.conditions[:]
@@ -2479,28 +2475,6 @@ def test_simple(self):
24792475
assert_almost_equal(tgt2, self.res2)
24802476
assert_(np.all(np.abs(tgt2) <= 1.0))
24812477

2482-
def test_ddof(self):
2483-
# ddof raises DeprecationWarning
2484-
with warnings.catch_warnings():
2485-
warnings.simplefilter("always")
2486-
pytest.warns(DeprecationWarning, corrcoef, self.A, ddof=-1)
2487-
warnings.simplefilter('ignore', DeprecationWarning)
2488-
# ddof has no or negligible effect on the function
2489-
assert_almost_equal(corrcoef(self.A, ddof=-1), self.res1)
2490-
assert_almost_equal(corrcoef(self.A, self.B, ddof=-1), self.res2)
2491-
assert_almost_equal(corrcoef(self.A, ddof=3), self.res1)
2492-
assert_almost_equal(corrcoef(self.A, self.B, ddof=3), self.res2)
2493-
2494-
def test_bias(self):
2495-
# bias raises DeprecationWarning
2496-
with warnings.catch_warnings():
2497-
warnings.simplefilter("always")
2498-
pytest.warns(DeprecationWarning, corrcoef, self.A, self.B, 1, 0)
2499-
pytest.warns(DeprecationWarning, corrcoef, self.A, bias=0)
2500-
warnings.simplefilter('ignore', DeprecationWarning)
2501-
# bias has no or negligible effect on the function
2502-
assert_almost_equal(corrcoef(self.A, bias=1), self.res1)
2503-
25042478
def test_complex(self):
25052479
x = np.array([[1, 2, 3], [1j, 2j, 3j]])
25062480
res = corrcoef(x)

numpy/ma/extras.py

Lines changed: 2 additions & 21 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,32 +1751,17 @@ 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-
bias : _NoValue, optional
1755-
Has no effect, do not use.
1756-
1757-
.. deprecated:: 1.10.0
17581754
allow_masked : bool, optional
17591755
If True, masked values are propagated pair-wise: if a value is masked
17601756
in `x`, the corresponding value is masked in `y`.
17611757
If False, raises an exception. Because `bias` is deprecated, this
17621758
argument needs to be treated as keyword only to avoid a warning.
1763-
ddof : _NoValue, optional
1764-
Has no effect, do not use.
1765-
1766-
.. deprecated:: 1.10.0
17671759
17681760
See Also
17691761
--------
17701762
numpy.corrcoef : Equivalent function in top-level NumPy module.
17711763
cov : Estimate the covariance matrix.
17721764
1773-
Notes
1774-
-----
1775-
This function accepts but discards arguments `bias` and `ddof`. This is
1776-
for backwards compatibility with previous versions of this function. These
1777-
arguments had no effect on the return values of the function and can be
1778-
safely ignored in this and previous versions of numpy.
1779-
17801765
Examples
17811766
--------
17821767
>>> import numpy as np
@@ -1791,10 +1776,6 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, allow_masked=True,
17911776
dtype=float64)
17921777
17931778
"""
1794-
msg = 'bias and ddof have no effect and are deprecated'
1795-
if bias is not np._NoValue or ddof is not np._NoValue:
1796-
# 2015-03-15, 1.10
1797-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
17981779
# Estimate the covariance matrix.
17991780
corr = cov(x, y, rowvar, allow_masked=allow_masked)
18001781
# The non-masked version returns a masked value for a scalar.

0 commit comments

Comments
 (0)