<class '_rdf_utils.numpy.array'> cannot be pickled using shelve. This is unusual as other ROOT types, e.g., TH1F, can be. If possible, it would be convenient if this feature were incorporated. Demonstration follows.
import ROOT
df = ROOT.RDataFrame(tchain)
ar = df.AsNumpy(columns=['P', 'PT'])
import shelve
shelf = shelve.open('test', 'c')
ar cannot be pickled directly:
shelf['ar'] = ar
results in:
---------------------------------------------------------------------------
PicklingError Traceback (most recent call last)
<ipython-input-10-26cba91d0728> in <module>()
----> 1 shelf['ar'] = ar
//anaconda2/lib/python2.7/shelve.pyc in __setitem__(self, key, value)
130 f = StringIO()
131 p = Pickler(f, self._protocol)
--> 132 p.dump(value)
133 self.dict[key] = f.getvalue()
134
PicklingError: Can't pickle <class '_rdf_utils.numpy.array'>: attribute lookup _rdf_utils.numpy.array failed
If, however, I wrap _rdf_utils.numpy.array into a true numpy array, it works just fine:
import numpy as np
arreal = {key: np.array(val) for key, val in ar.iteritems()}
shelf['ar'] = arreal
shelf.close()
ROOT Version: 6.19/01
Platform: macOS
Compiler: Not Provided