[Numpy-tickets] [NumPy] #439: poly1d objects can not be pickled

NumPy numpy-tickets at scipy.net
Tue Jan 30 04:18:47 CST 2007


#439: poly1d objects can not be pickled
-----------------------+----------------------------------------------------
 Reporter:  tovrstra   |       Owner:  somebody
     Type:  defect     |      Status:  new     
 Priority:  normal     |   Milestone:          
Component:  numpy.lib  |     Version:  1.0.1   
 Severity:  normal     |    Keywords:          
-----------------------+----------------------------------------------------
 Due to a bug in the {{{__getattr__}}} method of the {{{poly1d}}} class,
 instances of this class can not be pickled. The current version of the
 method is like this (in file {{{numpy/lib/polynomial.py}}}):

 {{{
     def __getattr__(self, key):
         if key in ['r', 'roots']:
             return roots(self.coeffs)
         elif key in ['c','coef','coefficients']:
             return self.coeffs
         elif key in ['o']:
             return self.order
         else:
             return self.__dict__[key]
 }}}

 while it should be something like this:

 {{{
     def __getattr__(self, key):
         if key in ['r', 'roots']:
             return roots(self.coeffs)
         elif key in ['c','coef','coefficients']:
             return self.coeffs
         elif key in ['o']:
             return self.order
         elif key not in self.__dict__:
             raise AttributeError("'%s' has not attribute '%s'" %
 (self.__class__, key))
         else:
             return self.__dict__[key]
 }}}

 In the original version a {{{KeyError}}} is raised when one tries to
 access a non-existing attribute, while an {{{AttributeError}}} should be
 raised. This confuses the pickle process since it tries to access the
 method {{{__getstate__}}} as an attribute and it expects an
 {{{AttributeError}}} to be raised when this method does not exist. I have
 tested the new version and it works.

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


More information about the Numpy-tickets mailing list