Closed
Description
Describe the issue:
In the nightly release, if an unhashable object is passed to np.finfo
the result is a TypeError
. In the most recent numpy release this is fine. This likely regressed in #23088
Reproduce the code example:
# current NumPy version
import numpy as np
class NonHashableWithDtype:
__hash__ = None
dtype = np.dtype('float32')
x = NonHashableWithDtype()
print(np.__version__) # 1.22.4
print(np.finfo(x).dtype) # float32
# nightly numpy version
import numpy as np
class NonHashableWithDtype:
__hash__ = None
dtype = np.dtype('float32')
x = NonHashableWithDtype()
print(np.__version__) # 1.22.4
print(np.finfo(x).dtype) # TypeError: unhashable type: 'NonHashableWithDtype'
Error message:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-74122a6c644f> in <cell line: 10>()
8
9 print(np.__version__) # 1.22.4
---> 10 print(np.finfo(x).dtype) # float32
/usr/local/lib/python3.10/dist-packages/numpy/core/getlimits.py in __new__(cls, dtype)
483
484 def __new__(cls, dtype):
--> 485 obj = cls._finfo_cache.get(dtype) # most common path
486 if obj is not None:
487 return obj
TypeError: unhashable type: 'NonHashableWithDtype'
Runtime information:
$ python -c "import numpy; print(numpy.show_runtime()
[{'numpy_version': '1.25.0.dev0+1465.g126b46c7a',
'python': '3.10.11 (main, Apr 5 2023, 14:15:10) [GCC 9.4.0]',
'uname': uname_result(system='Linux', node='018ecd4e5eb3', release='5.15.107+', version='#1 SMP Sat Apr 29 09:15:28 UTC 2023', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Zen',
'filepath': '/usr/local/lib/python3.10/dist-packages/numpy.libs/libopenblas64_p-r0-7a851222.3.23.so',
'internal_api': 'openblas',
'num_threads': 2,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.23'}]
Context for the issue:
This causes JAX unit tests to fail with the nightly numpy version: https://github.com/google/jax/actions/runs/4689008012/jobs/8310218419