[Numpy-tickets] [NumPy] #251: pickling numpy types

NumPy numpy-tickets at scipy.net
Wed Aug 16 13:53:13 CDT 2006


#251: pickling numpy types
------------------------+---------------------------------------------------
 Reporter:  IljyaKalai  |       Owner:  somebody    
     Type:  defect      |      Status:  new         
 Priority:  normal      |   Milestone:              
Component:  numpy.core  |     Version:              
 Severity:  minor       |    Keywords:  pickle, type
------------------------+---------------------------------------------------
 Trying to pickle numpy types raises an error.


 {{{
 >>> import numpy
 >>> import pickle
 >>> pickle.dumps(numpy.float32)
 PicklingError: Can't pickle <type 'float32_arrtype'>: it's not found as
 __builtin__.float32_arrtype

 }}}

 I believe this is because the types' module attribute is set to
 __builtin__ instead of numpy.


 {{{
 >>> import numpy
 >>> numpy.float32.__module__

 '__builtin__'
 }}}


 For anyone else needing this functionality, I am using the following work
 around:

 {{{

 >>> import numpy
 >>> import pickle
 >>> import __builtin__
 >>> __builtin__.float32_arrtype = numpy.float32
 >>> pickle.dumps(numpy.float32)
 'c__builtin__\nfloat32_arrtype\np0\n.'
 }}}


 The name binding must also be done when unpickling.

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/251>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list