Skip to content
Next Next commit
MAINT: remove deprecated trapz function, disp method and `bias/dd…
…of` args in `corrcoef`

This commit removes long-deprecated code paths in `numpy/lib/_function_base_impl`:
- Removed `numpy.trapz`, deprecated in NumPy 2.0 (2023-08-18)
- Removed `disp` method
- Removed `bias` and `ddof` arguments from `numpy.corrcoef`
Removed associated tests from `numpy/lib/tests/test_function_base.py` and
  `numpy/_core/test_deprecations.py`

Associated tests and type stubs were also updated.
All tests and Ruff checks pass locally.
  • Loading branch information
Abhi210 committed Oct 16, 2025
commit e4d64414394cbb2ae62e0f61c3230ba88f537090
1 change: 0 additions & 1 deletion numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@
sinc,
sort_complex,
trapezoid,
trapz,
trim_zeros,
unwrap,
vectorize,
Expand Down
3 changes: 1 addition & 2 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ from numpy.lib._function_base_impl import ( # type: ignore[deprecated]
blackman,
kaiser,
trapezoid,
trapz,
i0,
meshgrid,
delete,
Expand Down Expand Up @@ -686,7 +685,7 @@ __all__ = [ # noqa: RUF022
"gradient", "angle", "unwrap", "sort_complex", "flip", "rot90", "extract", "place",
"vectorize", "asarray_chkfinite", "average", "bincount", "digitize", "cov",
"corrcoef", "median", "sinc", "hamming", "hanning", "bartlett", "blackman",
"kaiser", "trapezoid", "trapz", "i0", "meshgrid", "delete", "insert", "append",
"kaiser", "trapezoid", "i0", "meshgrid", "delete", "insert", "append",
"interp", "quantile",
# lib._twodim_base_impl.__all__
"diag", "diagflat", "eye", "fliplr", "flipud", "tri", "triu", "tril", "vander",
Expand Down
5 changes: 1 addition & 4 deletions numpy/_core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ def test_deprecated_np_lib_math(self):
class TestLibImports(_DeprecationTestCase):
# Deprecated in Numpy 1.26.0, 2023-09
def test_lib_functions_deprecation_call(self):
from numpy import row_stack, trapz
from numpy import row_stack
from numpy._core.numerictypes import maximum_sctype
from numpy.lib._function_base_impl import disp
from numpy.lib._npyio_impl import recfromcsv, recfromtxt
from numpy.lib._shape_base_impl import get_array_wrap
from numpy.lib._utils_impl import safe_eval
Expand All @@ -295,12 +294,10 @@ def test_lib_functions_deprecation_call(self):
self.assert_deprecated(lambda: recfromcsv(data_gen()))
self.assert_deprecated(lambda: recfromtxt(data_gen(), **kwargs))

self.assert_deprecated(lambda: disp("test"))
self.assert_deprecated(get_array_wrap)
self.assert_deprecated(lambda: maximum_sctype(int))

self.assert_deprecated(lambda: row_stack([[]]))
self.assert_deprecated(lambda: trapz([1], [1]))
self.assert_deprecated(lambda: np.chararray)


Expand Down
1 change: 0 additions & 1 deletion numpy/_expired_attrs_2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"or use `typing.deprecated`.",
"deprecate_with_doc": "Emit `DeprecationWarning` with `warnings.warn` "
"directly, or use `typing.deprecated`.",
"disp": "Use your own printing function instead.",
"find_common_type":
"Use `numpy.promote_types` or `numpy.result_type` instead. "
"To achieve semantics for the `scalar_types` argument, use "
Expand Down
1 change: 0 additions & 1 deletion numpy/_expired_attrs_2_0.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class _ExpiredAttributesType(TypedDict):
recfromtxt: str
deprecate: str
deprecate_with_doc: str
disp: str
find_common_type: str
round_: str
get_array_wrap: str
Expand Down
88 changes: 1 addition & 87 deletions numpy/lib/_function_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import collections.abc
import functools
import re
import sys
import warnings

import numpy as np
Expand Down Expand Up @@ -68,7 +67,7 @@
'rot90', 'extract', 'place', 'vectorize', 'asarray_chkfinite', 'average',
'bincount', 'digitize', 'cov', 'corrcoef',
'median', 'sinc', 'hamming', 'hanning', 'bartlett',
'blackman', 'kaiser', 'trapezoid', 'trapz', 'i0',
'blackman', 'kaiser', 'trapezoid', 'i0',
'meshgrid', 'delete', 'insert', 'append', 'interp',
'quantile'
]
Expand Down Expand Up @@ -2119,62 +2118,6 @@ def place(arr, mask, vals):
return _place(arr, mask, vals)


def disp(mesg, device=None, linefeed=True):
"""
Display a message on a device.

.. deprecated:: 2.0
Use your own printing function instead.

Parameters
----------
mesg : str
Message to display.
device : object
Device to write message. If None, defaults to ``sys.stdout`` which is
very similar to ``print``. `device` needs to have ``write()`` and
``flush()`` methods.
linefeed : bool, optional
Option whether to print a line feed or not. Defaults to True.

Raises
------
AttributeError
If `device` does not have a ``write()`` or ``flush()`` method.

Examples
--------
>>> import numpy as np

Besides ``sys.stdout``, a file-like object can also be used as it has
both required methods:

>>> from io import StringIO
>>> buf = StringIO()
>>> np.disp('"Display" in a file', device=buf)
>>> buf.getvalue()
'"Display" in a file\\n'

"""

# Deprecated in NumPy 2.0, 2023-07-11
warnings.warn(
"`disp` is deprecated, "
"use your own printing function instead. "
"(deprecated in NumPy 2.0)",
DeprecationWarning,
stacklevel=2
)

if device is None:
device = sys.stdout
if linefeed:
device.write(f'{mesg}\n')
else:
device.write(f'{mesg}')
device.flush()


# See https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
_DIMENSION_NAME = r'\w+'
_CORE_DIMENSION_LIST = f'(?:{_DIMENSION_NAME}(?:,{_DIMENSION_NAME})*)?'
Expand Down Expand Up @@ -2959,14 +2902,7 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
variable, with observations in the columns. Otherwise, the relationship
is transposed: each column represents a variable, while the rows
contain observations.
bias : _NoValue, optional
Has no effect, do not use.

.. deprecated:: 1.10.0
ddof : _NoValue, optional
Has no effect, do not use.

.. deprecated:: 1.10.0
dtype : data-type, optional
Data-type of the result. By default, the return data-type will have
at least `numpy.float64` precision.
Expand Down Expand Up @@ -3061,10 +2997,6 @@ def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, ddof=np._NoValue, *,
1. ]])

"""
if bias is not np._NoValue or ddof is not np._NoValue:
# 2015-03-15, 1.10
warnings.warn('bias and ddof have no effect and are deprecated',
DeprecationWarning, stacklevel=2)
c = cov(x, y, rowvar, dtype=dtype)
try:
d = diag(c)
Expand Down Expand Up @@ -5080,24 +5012,6 @@ def trapezoid(y, x=None, dx=1.0, axis=-1):
return ret


@set_module('numpy')
def trapz(y, x=None, dx=1.0, axis=-1):
"""
`trapz` is deprecated in NumPy 2.0.

Please use `trapezoid` instead, or one of the numerical integration
functions in `scipy.integrate`.
"""
# Deprecated in NumPy 2.0, 2023-08-18
warnings.warn(
"`trapz` is deprecated. Use `trapezoid` instead, or one of the "
"numerical integration functions in `scipy.integrate`.",
DeprecationWarning,
stacklevel=2
)
return trapezoid(y, x=x, dx=dx, axis=axis)


def _meshgrid_dispatcher(*xi, copy=None, sparse=None, indexing=None):
return xi

Expand Down
7 changes: 1 addition & 6 deletions numpy/lib/_function_base_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from typing import (
overload,
type_check_only,
)
from typing_extensions import TypeIs, deprecated
from typing_extensions import TypeIs

import numpy as np
from numpy import (
Expand Down Expand Up @@ -87,7 +87,6 @@ __all__ = [
"blackman",
"kaiser",
"trapezoid",
"trapz",
"i0",
"meshgrid",
"delete",
Expand Down Expand Up @@ -990,10 +989,6 @@ def trapezoid(
floating | complexfloating | timedelta64
| NDArray[floating | complexfloating | timedelta64 | object_]
): ...

@deprecated("Use 'trapezoid' instead")
def trapz(y: ArrayLike, x: ArrayLike | None = None, dx: float = 1.0, axis: int = -1) -> generic | NDArray[generic]: ...

@overload
def meshgrid(
*,
Expand Down
26 changes: 0 additions & 26 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,6 @@ def test_return_dtype(self):
m = np.isnan(d)
assert_equal(select([m], [d]), [0, 0, 0, np.nan, 0, 0])

def test_deprecated_empty(self):
assert_raises(ValueError, select, [], [], 3j)
assert_raises(ValueError, select, [], [])

def test_non_bool_deprecation(self):
choices = self.choices
conditions = self.conditions[:]
Expand Down Expand Up @@ -2476,28 +2472,6 @@ def test_simple(self):
assert_almost_equal(tgt2, self.res2)
assert_(np.all(np.abs(tgt2) <= 1.0))

def test_ddof(self):
# ddof raises DeprecationWarning
with warnings.catch_warnings():
warnings.simplefilter("always")
pytest.warns(DeprecationWarning, corrcoef, self.A, ddof=-1)
warnings.simplefilter('ignore', DeprecationWarning)
# 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 warnings.catch_warnings():
warnings.simplefilter("always")
pytest.warns(DeprecationWarning, corrcoef, self.A, self.B, 1, 0)
pytest.warns(DeprecationWarning, corrcoef, self.A, bias=0)
warnings.simplefilter('ignore', DeprecationWarning)
# 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]])
res = corrcoef(x)
Expand Down
1 change: 0 additions & 1 deletion numpy/matlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ from numpy import ( # noqa: F401
trace,
transpose,
trapezoid,
trapz,
tri,
tril,
tril_indices,
Expand Down
Loading