diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py index da9e1d7f311c..13414c2a64d6 100644 --- a/numpy/core/getlimits.py +++ b/numpy/core/getlimits.py @@ -482,9 +482,12 @@ class finfo: _finfo_cache = {} def __new__(cls, dtype): - obj = cls._finfo_cache.get(dtype) # most common path - if obj is not None: - return obj + try: + obj = cls._finfo_cache.get(dtype) # most common path + if obj is not None: + return obj + except TypeError: + pass if dtype is None: # Deprecated in NumPy 1.25, 2023-01-16 diff --git a/numpy/core/tests/test_getlimits.py b/numpy/core/tests/test_getlimits.py index 63217c38c098..f646e2bd7980 100644 --- a/numpy/core/tests/test_getlimits.py +++ b/numpy/core/tests/test_getlimits.py @@ -73,6 +73,15 @@ def test_regression_gh23108(self): f2 = np.finfo(np.float64(1.0)) assert f1 != f2 + def test_regression_gh23867(self): + class NonHashableWithDtype: + __hash__ = None + dtype = np.dtype('float32') + + x = NonHashableWithDtype() + assert np.finfo(x) == np.finfo(x.dtype) + + class TestIinfo: def test_basic(self): dts = list(zip(['i1', 'i2', 'i4', 'i8',