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
{{ message }}
Repository navigation
Cannot pickle figure or axes (TypeError: instancemethod) #3392
@kratsg - I've been triaging a few pickle bugs, but unfortunately I've not been able to test your code as it isn't a self contained example (imports and data needed). As a result, I will try to fix a few of the issues highlighted, but I may miss some of those that you are seeing. If you have some data and the necessary imports, please would you be willing to update the issue report with the necessaries?
For the record, I diagnosed the problem by calling recursive_pickle(ax) which can be found in matplotlib/tests/test_pickle.py.
The result:
<bound method Line2D._draw_dotted of <matplotlib.lines.Line2D object at 0x46a6690>>
Failed to pickle attribute "_lineFunc" in (attribute "gridline" in (list/tuple item #0 in (attribute "majorTicks" in (attribute "xaxis" in (top level object)))))
Next step is to look for where _lineFunc is added to the gridline - I went to the Axes class, found that def grid calls the grid method on an Axis, so went there, and the trail went cold. So instead I grepped for _lineFunc (nothing like bruteforce 😉) and found that it is attached to a line in lines.py. Fixing commit added to the PR (f1e43ed).
Pickling can be quite a pain. ;) I've had to write some of my own custom pickle handlers for various cython code I'm working on. This looks great, albeit slightly convoluted.
Several other of the most common packages have started allowing an override of pickle to enable people to use dill or another custom pickler to serialize their code… matplotlib could do the same. Please ping me if you have any questions about the above, or dill, or otherwise.
Several other of the most common packages have started allowing an override of pickle to enable people to use dill or another custom pickler to serialize their code…
Hmmm. Might be a good idea - mpl makes fairly regular use of instancemethods as attributes to be called at draw time, so automatic pickling of those would be quite pleasant.
Activity
tacaswell commentedon Aug 21, 2014
what version of mpl? Can you test with 1.4.0rc4?
kratsg commentedon Aug 21, 2014
mpl version 1.3.1 . I can check 1.4.0rc4 later, but I was kind of expecting that it would be more or less "working" with 1.3.x
tacaswell commentedon Aug 21, 2014
There was a bunch of work done in the last year on pickling so it might already be fixed (just not released).
Once we release 1.4.0 (which should be very soon) we will no longer support the 1.3 series.
pelson commentedon Oct 9, 2014
@kratsg - I've been triaging a few pickle bugs, but unfortunately I've not been able to test your code as it isn't a self contained example (imports and data needed). As a result, I will try to fix a few of the issues highlighted, but I may miss some of those that you are seeing. If you have some data and the necessary imports, please would you be willing to update the issue report with the necessaries?
Thanks,
kratsg commentedon Oct 9, 2014
@pelson , you should be able to do something like:
which is self-contained.
pelson commentedon Oct 9, 2014
Great! Thanks for the quick response. My PR (#3627) appears to have fixed the problem without the grid, but the following will still fail:
I'll take a look at this and add it to the PR.
Thanks.
pelson commentedon Oct 9, 2014
For the record, I diagnosed the problem by calling
recursive_pickle(ax)which can be found inmatplotlib/tests/test_pickle.py.The result:
Next step is to look for where
_lineFuncis added to the gridline - I went to the Axes class, found thatdef gridcalls thegridmethod on an Axis, so went there, and the trail went cold. So instead I grepped for_lineFunc(nothing like bruteforce 😉) and found that it is attached to a line inlines.py. Fixing commit added to the PR (f1e43ed).kratsg commentedon Oct 9, 2014
Pickling can be quite a pain. ;) I've had to write some of my own custom pickle handlers for various cython code I'm working on. This looks great, albeit slightly convoluted.
mmckerns commentedon Oct 9, 2014
@pelson: aside from the mention of
dill.detectin uqfoundation/dill#4,I should point you to the following files, which contains all the known types that
dillcan pickle, and the custom picklers:https://github.com/uqfoundation/dill/blob/master/dill/_objects.py
https://github.com/uqfoundation/dill/blob/master/dill/dill.py
Several other of the most common packages have started allowing an override of
pickleto enable people to usedillor another custom pickler to serialize their code…matplotlibcould do the same. Please ping me if you have any questions about the above, ordill, or otherwise.pelson commentedon Oct 10, 2014
Hmmm. Might be a good idea - mpl makes fairly regular use of instancemethods as attributes to be called at draw time, so automatic pickling of those would be quite pleasant.
The mpl codebase has needed a fair amount of custom getstate/setstate overrides in order to deal with those cases and a few other niceties (e.g. https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/figure.py#L1299).
tacaswell commentedon Oct 10, 2014
@pelson Closing this as I think that #3627 fixes both issues