diff --git a/doc/release/upcoming_changes/23011.deprecation.rst b/doc/release/upcoming_changes/23011.deprecation.rst new file mode 100644 index 000000000000..72168ff87d4b --- /dev/null +++ b/doc/release/upcoming_changes/23011.deprecation.rst @@ -0,0 +1 @@ +* ``np.finfo(None)`` is deprecated. diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py index 5baeb97fe363..8146c46449ca 100644 --- a/numpy/core/getlimits.py +++ b/numpy/core/getlimits.py @@ -471,6 +471,15 @@ class finfo: _finfo_cache = {} def __new__(cls, dtype): + if dtype is None: + # Deprecated in NumPy 1.25, 2023-01-16 + warnings.warn( + "finfo() dtype cannot be None. This behavior will " + "raise an error in the future. (Deprecated in NumPy 1.25)", + DeprecationWarning, + stacklevel=2 + ) + try: dtype = numeric.dtype(dtype) except TypeError: diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 83777cc9cd18..d82ae001c66f 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -1107,3 +1107,9 @@ def test_attributeerror_includes_info(self, name): msg = f".*\n`np.{name}` was a deprecated alias for the builtin" with pytest.raises(AttributeError, match=msg): getattr(np, name) + + +class TestDeprecatedFinfo(_DeprecationTestCase): + # Deprecated in NumPy 1.25, 2023-01-16 + def test_deprecated_none(self): + self.assert_deprecated(np.finfo, args=(None,))