-
-
Notifications
You must be signed in to change notification settings - Fork 11k
PyPy3 TypeError: 'numpy.float64' objects are unhashable #8887
New issue
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
Comments
I think the difference is: >>> print(np.float16.__hash__)
<slot wrapper '__hash__' of 'numpy.float16' objects>
>>> print(np.float32.__hash__)
<slot wrapper '__hash__' of 'numpy.float32' objects>
>>> print(np.float64.__hash__)
None Because Could this be a bug to do with hashing and multiple inheritance in PyPy? |
This is almost certainly related somehow to the fact that float64 is a subclass of float (the built-in type), and the other floatXX classes aren't. |
I'm super confused here though - why is it legal to call >>> class MyFloat(float):
__hash__ = None
>>> mf = MyFloat(1)
>>> nf = np.float64(1)
>>> mf.__hash__
>>> hash(mf)
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
hash(mf)
TypeError: unhashable type: 'MyFloat'
>>> nf.__hash__
>>> hash(nf)
1 I thought that |
I tried debugging this in PyPy, but got bogged down trying to understand how exactly numpy initialises the types. The situation on CPython is quite dodgy, since |
@eric-wieser: I'm not sure what's going on with @peterjc: you should also check your intXX objects -- I bet either int32 or int64 has the same bug (depending on how large your platform's |
@njsmith Nope, the issue exists only with |
wut |
@njsmith Sorry, it's not a descriptor, it's just a |
Found the bug, patch incoming... |
The culprit is the It seems that the fix is just to set |
@rlamy: Indeed, that's the patch I have |
This would previously cause hashing to work even though `__hash__` is None. Fixes numpy#8887
@peterjc: Does this fix PyPy? |
@eric-wieser Yes, it fixes it. |
Excellent work everyone - thank you. I'll look forward to this working in the next NumPy release :) |
This closes GitHub issue #1112 where under PyPy3.5 v5.7 beta a bug in NumPy 1.12.1 makes numpy.float64 unhashable. See numpy/numpy#8887
This closes GitHub issue biopython#1112 where under PyPy3.5 v5.7 beta a bug in NumPy 1.12.1 makes numpy.float64 unhashable. See numpy/numpy#8887
There is a bug in Numpy 1.12.1 that cause the previous approach to break: numpy/numpy#8887
* beginning overhaul of random processes * fixing random process behavior * fixing bug with infinite samples from BoxModel * removing unused imports * fixing bug with cumsum * TODO for result.py * adding plotting for Vectors and other result objects * fixing problems with RandomProcess * fixing issues with joining and hashing of Vectors * move RandomProcess functionality to RV, fix plotting * replacing references to RandomProcess with RV, fixing bugs with Vector * stripping RandomProcess of most methods * fixing bugs with hashing and comparison of Vectors * fixing a few bugs with plotting * fixed speed issue with RandomProcess * Fix error with scalar types not being recognized * fixing problems with composition of RV and Result objects * switching order of drift and scale parameters * allow random processes to be combined with Vectors * changing default index set of RandomProcess to Naturals() * Change is_hashable() There is a bug in Numpy 1.12.1 that cause the previous approach to break: numpy/numpy#8887 * change order of arguments for Brownian motion * fix bug with standard math functions * change how Vectors are stored and joined * distinguish between tuple and Tuple * replace isinstance(x, int) by the more robust isinstance( numbers.Integral) * check for numpy float types * allowing joint distributions to be defined with scalars * adding concat function * allow Vectors to be added to tuples and lists * fixing how arrays are set in Vector * vectorize Vector operations * Vectors can now store arbitrary objects * fixing bug with MultivariateNormal * fixing typo in commit 20728b * fixing bug with RVResults that was preventing random processes from being plotted * creating Tuple and Vector classes * fixing bug with Tuple * changing behavior of Tuple and Vector append * fixing bug with corr, random processes, and sorting for .tabulate() * fixing DeckOfCards * making all things Vectors, Tuples only returned by * * making Tuples compatible with generators * using generators throughout * removing vectorized operations for now
* beginning overhaul of random processes * fixing random process behavior * fixing bug with infinite samples from BoxModel * removing unused imports * fixing bug with cumsum * TODO for result.py * adding plotting for Vectors and other result objects * fixing problems with RandomProcess * fixing issues with joining and hashing of Vectors * move RandomProcess functionality to RV, fix plotting * replacing references to RandomProcess with RV, fixing bugs with Vector * stripping RandomProcess of most methods * fixing bugs with hashing and comparison of Vectors * fixing a few bugs with plotting * fixed speed issue with RandomProcess * Fix error with scalar types not being recognized * fixing problems with composition of RV and Result objects * switching order of drift and scale parameters * allow random processes to be combined with Vectors * changing default index set of RandomProcess to Naturals() * Change is_hashable() There is a bug in Numpy 1.12.1 that cause the previous approach to break: numpy/numpy#8887 * change order of arguments for Brownian motion * fix bug with standard math functions * change how Vectors are stored and joined * distinguish between tuple and Tuple * replace isinstance(x, int) by the more robust isinstance( numbers.Integral) * check for numpy float types * allowing joint distributions to be defined with scalars * adding concat function * allow Vectors to be added to tuples and lists * fixing how arrays are set in Vector * vectorize Vector operations * Vectors can now store arbitrary objects * fixing bug with MultivariateNormal * fixing typo in commit 20728b * fixing bug with RVResults that was preventing random processes from being plotted * creating Tuple and Vector classes * fixing bug with Tuple * changing behavior of Tuple and Vector append * fixing bug with corr, random processes, and sorting for .tabulate() * fixing DeckOfCards * making all things Vectors, Tuples only returned by * * making Tuples compatible with generators * using generators throughout * removing vectorized operations for now * Adding Multinomial, Fixing Pareto (#75) * Fixing Pareto tests * Adding Multinomial, Fixing Pareto
Cross reference PyPy issue: https://bitbucket.org/pypy/pypy/issues/2479/numpyfloat64-objects-are-unhashable
I'm logging this here for reference, and on the off chance that someone on the NumPy team could say why
numpy.float64
might behave so differently from the other size floats under PyPy3.Expected behaviour, showing Python 3.5.0 in 64-bit Linux:
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
The other float types seem to hash fine, but
numpy.float64
does not under PyPy3.5 v5.7 beta.The text was updated successfully, but these errors were encountered: