Skip to content

Commit

Permalink
DEP: deprecate np.finfo(None) (#23011)
Browse files Browse the repository at this point in the history
Deprecate np.finfo(None), it may be that we should more generally deprecate `np.dtype(None)` but this is a start and particularly weird maybe.

Closes gh-14684
  • Loading branch information
dshintani404 committed Jan 19, 2023
1 parent e2fccd9 commit 0cfbd3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/release/upcoming_changes/23011.deprecation.rst
@@ -0,0 +1 @@
* ``np.finfo(None)`` is deprecated.
9 changes: 9 additions & 0 deletions numpy/core/getlimits.py
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_deprecations.py
Expand Up @@ -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,))

0 comments on commit 0cfbd3c

Please sign in to comment.