8000 BUG: Allow np.info on non-hashable objects with a dtype (#23911) · numpy/numpy@d804796 · GitHub
[go: up one dir, main page]

Skip to content

Commit d804796

Browse files
authored
BUG: Allow np.info on non-hashable objects with a dtype (#23911)
In this PR we restore the functionality to call np.finfo on non-hashable objects with a dtype. Fixes #23867.
1 parent 151a51f commit d804796

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

numpy/core/getlimits.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,12 @@ class finfo:
482482
_finfo_cache = {}
483483

484484
def __new__(cls, dtype):
485-
obj = cls._finfo_cache.get(dtype) # most common path
486-
if obj is not None:
487-
return obj
485+
try:
486+
obj = cls._finfo_cache.get(dtype) # most common path
487+
if obj is not None:
488+
return obj
489+
except TypeError:
490+
pass
488491

489492
if dtype is None:
490493
# Deprecated in NumPy 1.25, 2023-01-16

numpy/core/tests/test_getlimits.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def test_regression_gh23108(self):
7373
f2 = np.finfo(np.float64(1.0))
7474
assert f1 != f2
7575

76+
def test_regression_gh23867(self):
77+
class NonHashableWithDtype:
78+
__hash__ = None
79+
dtype = np.dtype('float32')
80+
81+
x = NonHashableWithDtype()
82+
assert np.finfo(x) == np.finfo(x.dtype)
83+
84+
7685
class TestIinfo:
7786
def test_basic(self):
7887
dts = list(zip(['i1', 'i2', 'i4', 'i8',

0 commit comments

Comments
 (0)
0