AttributeError: 'module' object has no attribute '_RandomState__RandomState_ctor'

Issue #30 resolved
Kevin Keraudren created an issue
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)

  1. Armin Rigo

    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')

  2. Log in to comment