AttributeError: 'module' object has no attribute '_RandomState__RandomState_ctor'
import numpy as np
a = np.random.RandomState(5)
a.__reduce__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/homes/kpk09/.local/lib/pypy2.7/site-packages/numpy/random/mtrand.py", line 623, in __reduce__
return (np.random.__RandomState_ctor, (), self.get_state())
AttributeError: 'module' object has no attribute '_RandomState__RandomState_ctor'
Is pypy stricter that python on private methods, and prefixes everything starting with '__' by the class name?
A fix for the above bug is to rename __RandomState_ctor
to RandomState_ctor
in numpy/random/init.py and in numpy/random/mtrand.py.
Comments (5)
-
reporter -
It seems to me that CPython mangles names in the same cases. How can this line work in CPython?
-
Ah, that file doesn't exist in CPython: it has been introduced for PyPy only. The name "numpy.random.__RandomState_ctor" exists in both CPython and PyPy, so I'd suggest to fix the PyPy-only "mtrand.py" instead. Just say
getattr(np.random, '__RandomState_ctor')
-
reporter mtrand.py in Pypy/numpy corresponds to mtrand.pyx in CPython/numpy: https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/mtrand.pyx
-
- changed status to resolved
fix issue
#30→ <<cset 8ef1d0bb123d>>
- Log in to comment
See https://bitbucket.org/kevin-keraudren/numpy/commits/57b235218f763f9ac2af3bf403e9f8f0775300fc for patch