[pypy-issue] Issue #2518: pypy3 hashing numpy float types inconsistent / unhashable (pypy/pypy)

peterjc issues-reply at bitbucket.org
Fri Mar 24 10:48:50 EDT 2017


New issue 2518: pypy3 hashing numpy float types inconsistent / unhashable
https://bitbucket.org/pypy/pypy/issues/2518/pypy3-hashing-numpy-float-types

peterjc:

Desired behaviour, using Python 3.5.0 in 64-bit Linux:

```bash
$ python3
Python 3.5.0 (default, Sep 28 2015, 11:25:31) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> print(numpy.__version__)
1.12.1
>>> f = 123.456
>>> for t in [np.float, np.float16, np.float32, np.float64, np.float128]:
...     new = t(f)
...     print(hash(new), hash(new)==hash(f), t.__name__)
... 
1051464412201451643 True float
1008806316530991227 False float16
1051467367688700027 False float32
1051464412201451643 True float64
1051464412201451643 True float128
>>> quit()
>>> quit()
```

i.e. We expect all the floats to be hashable, and some types should have hash the same as Python's float.

Observed behaviour using PyPy3.5 v5.7 beta from https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3.5-5.7-beta-linux_x86_64-portable.tar.bz2

```bash
$ ~/Downloads/pypy3.5-5.7-beta-linux_x86_64-portable/bin/pypy
Python 3.5.3 (b16a4363e930f6401bceb499b9520955504c6cb0, Mar 21 2017, 12:36:24)
[PyPy 5.7.0-beta0 with GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``the world doesn't want us to
know''
>>>> import numpy as np
>>>> print(np.__version__)
1.12.1
>>>> f = 123.456
>>>> for t in [np.float, np.float16, np.float32, np.float64, np.float128]:
....     new = t(f)
....     print(t, hash(new), hash(new)==hash(f))
....     
<class 'float'> 1051464412201451643 True
<class 'numpy.float16'> 1008806316530991227 False
<class 'numpy.float32'> 1051467367688700027 False
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
TypeError: 'numpy.float64' objects are unhashable
>>>> 
>>>> 
>>>> for t in [np.float, np.float16, np.float16, np.float32, np.float64, np.float128]:
....     new = t(f)
....     print(hash(new), hash(new)==hash(f), t.__name__)
....     
1051464412201451643 True float
1008806316530991227 False float16
1008806316530991227 False float16
1051467367688700027 False float32
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
TypeError: 'numpy.float64' objects are unhashable
>>>> quit()
```

In both cases NumPy 1.12.1 was installed with pip.

Problem one: hash from ``numpy.float32`` is inconsistent (expected to match Python's float).

Problem two: ``numpy.float64`` is unhashable.




More information about the pypy-issue mailing list