pypy3 hashing numpy float32 types inconsistent

Issue #2518 duplicate
Peter Cock created an issue

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

$ 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

$ ~/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.float128, np.float64]:
....     new = t(f)
....     print(hash(new), hash(new)==hash(f), t.__name__)
....     
1051464412201451643 True float
1008806316530991227 False float16
1051467367688700027 False float32
1051464412201451643 True float128
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. (as noted below, filed as https://bitbucket.org/pypy/pypy/issues/2479/numpyfloat64-objects-are-unhashable already)

Comments (7)

  1. Ronan Lamy

    On CPython, np.float32 doesn't match float's hash either (which is expected since np.float32(123.456) != float(123.456)), so pypy's behaviour seems fine in this case.

  2. Peter Cock reporter

    You're right Roan - this can be closed as a duplicate of #2479.

    Otherwise the results do indeed match Python 3.5.0.

  3. Log in to comment