1. James Taylor
  2. bx-python
  3. Issues
Issue #44 new

Can't pickle IntervalTree objects

Davide Cittaro
created an issue

I'm working with IntervalTrees and I have some data structures which may be handy for my future work. Unfortunately I cannot dump them into a file using python pickle

pickle.dump(itc, open('Annotation.pkl', 'w'))

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in dump(obj, file, protocol)
   1368 
   1369 def dump(obj, file, protocol=None):
-> 1370     Pickler(file, protocol).dump(obj)
   1371 
   1372 def dumps(obj, protocol=None):

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in dump(self, obj)
    222         if self.proto >= 2:
    223             self.write(PROTO + chr(self.proto))
--> 224         self.save(obj)
    225         self.write(STOP)
    226 

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in save(self, obj)
    304             reduce = getattr(obj, "__reduce_ex__", None)
    305             if reduce:
--> 306                 rv = reduce(self.proto)
    307             else:
    308                 reduce = getattr(obj, "__reduce__", None)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.pyc in _reduce_ex(self, proto)
     68     else:
     69         if base is self.__class__:
---> 70             raise TypeError, "can't pickle %s objects" % base.__name__
     71         state = base(self)
     72     args = (self.__class__, base, state)

TypeError: can't pickle IntervalTree objects

would it be possible to add pickling support as described here http://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types

Comments (1)

  1. Log in to comment