You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have code that needs to pickle functions (i.e. for joblib) that are defined in modules where statsmodels.api is imported. The pickle attempt leads to an AttributeError from the statsmodels.graphics.functional module:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\[...]\lib\site-packages\statsmodels\graphics\functional.py", line 32, in _pickle_method
if m.im_self is None:
AttributeError: 'function' object has no attribute 'im_self'
This can be simply reproduced by creating a short module with the following code:
import statsmodels.api as sm
class Dummy(object):
def __init__(self):
pass
def get_add_constant(self):
return sm.add_constant
If this code is saved in a file, test_mod.py, then I can trigger the exception by opening a python session and entering:
>>> from test_mod import Dummy
>>> dum = Dummy()
>>> pickle.dumps(dum.get_add_constant)
I have worked around the issue by narrowing my import to just the classes needed in my code, but this seems like a bug in graphics.functional that should be addressed.
Note: I observed this issue using statsmodels 0.9.0 in Windows.
I can replicate it as soon as statsmodels.api is imported, even when it is not used.
That is, copyreg in graphics changes the global registry which messes up pickling in other parts of statsmodels.
I don't know yet what the fix is,
Do we adjust the pickle_method in graphics functional or do we drop it completely?
I don't think some specific module should change globals or global settings, i.e. if we need to change a global registry, then it should go into tools like exceptions and warnings.
pickle.dump(obj=obj, file=f, protocol=4)
File "/home/****/env/lib/python3.6/site-packages/statsmodels/graphics/functional.py", line 32, in _pickle_method
if m.im_self is None:
AttributeError: 'function' object has no attribute 'im_self'
Can we get a 0.9.1 for this bug? It is causing big problems for my team. Downgrading to 0.8.0 causes problems compiling a wheel that do not seem to be present with 0.9.0.
Activity
josef-pkt commentedon Jul 5, 2018
@EricWrightAtWork Thanks for reporting.
I can replicate it as soon as statsmodels.api is imported, even when it is not used.
That is, copyreg in graphics changes the global registry which messes up pickling in other parts of statsmodels.
I don't know yet what the fix is,
Do we adjust the pickle_method in graphics functional or do we drop it completely?
I don't think some specific module should change globals or global settings, i.e. if we need to change a global registry, then it should go into tools like exceptions and warnings.
pseudotensor commentedon Jul 26, 2018
I get same error for 0.9.0 but not 0.8.0.
BUG: Remove change of global pickle method
BUG: Remove change of global pickle method
BUG: Remove change of global pickle method
BUG: Remove change of global pickle method
BUG: Remove change of global pickle method
BUG: Remove change of global pickle method
jfindlay commentedon Nov 19, 2018
Can we get a 0.9.1 for this bug? It is causing big problems for my team. Downgrading to 0.8.0 causes problems compiling a wheel that do not seem to be present with 0.9.0.
jfindlay commentedon Nov 20, 2018
For anyone who encounters this bug, here is a workaround I am using for 0.9.0:
mhooreman commentedon Jan 14, 2019
Hello,
When will the fix be available on pip? I need that for production servers, where I had to force statsmodels<0.9.
Thanks a lot.
rebecca-palmer commentedon Sep 19, 2019
pip has 0.10 which includes this fix; no incompatible changes are specifically listed in the release notes, but I haven't checked further.
The fix (#4963) looks like it may well work in 0.9, but I haven't had time to test it.