When I try to save a ROOT object using shelve, it panics and fails. This started happening after I brought my local build up-to-date with the master branch–I am not sure what changes caused the problem. Reproducer follows. Output attached.
import shelve
import ROOT
df = ROOT.RDataFrame(10).Define('e', 'rdfentry_')
h = df.Histo1D('e')
shelf = shelve.open('test', 'n')
shelf['h'] = h
ROOT Version: master Platform: macOS Compiler: Not Provided
Hi,
at what commit was your local build before? Recently, for some definition of recently, ROOT master has switched to a completely new version of PyROOT. My first guess would be that. You can see if switching -Dpyroot_experimental=OFF when building fixes the problem, if yes, that’s it, and I guess you should open a jira ticket.
The regular pickling works in master with the new PyROOT:
>>> import ROOT, pickle
>>> h = ROOT.TH1D()
>>> pickle.dumps ( h )
b'\x80\x03clibROOTPythonizations3_7\n_CPPInstance__expand__\nq\x00B1\x02\x00\x00@\x00\x02-\xff\xff\xff\xffTH1D\x00@\x00\x02 \x00\x03@\x00\x01\xfe\x00\x08@\x00\x00\x0e\x00\x01\x00\x01\x00\x00\x00\x00\x03\x00\x00\...'
From what I see in the error stack you sent, shelve uses cPickle:
[/Users/michael/anaconda2/lib/python2.7/lib-dynload/cPickle.so] save (no debug info)
[/Users/michael/anaconda2/lib/python2.7/lib-dynload/cPickle.so] Pickler_dump (no debug info)
If I try the code above the cPickle instead of pickle it also works.
I don’t know how exactly shelve uses cPickle to trigger that error. Do you know what are the requirements of shelve with respect to the objects to be “shelved”?
Yes, indeed you found the reason. We can’t serialize RResultPtrs (which is what e.g. Histo1D returns) because they contain a shared pointer to the underlying object, and we can’t serialize shared pointers at the moment.
You can also use GetValue to get the underlying object and shelve that.