8000 BUG: Allow np.info on non-hashable objects with a dtype by eendebakpt · Pull Request #23911 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Allow np.info on non-hashable objects with a dtype #23911

New issue
8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions numpy/core/getlimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions numpy/core/tests/test_getlimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
0