[SciPy-user] __setstate__ of TimeSeries subclass

Pijus Virketis pijus@virketis....
Thu Apr 24 15:51:04 CDT 2008


Hi,

I am trying to get the __setstate__ method working on a subclass of
scikits.TimeSeries.

The setup:

from scikits.timeseries import *

class Test(TimeSeries):
    def __new__(cls, *args, **kwargs):
        return(TimeSeries.__new__(cls, [], date_array([])))

test = Test()
# works fine
print(repr(test))


The problem:

# one-observation TimeSeries instance
ts = time_series([1], date_array([Date(string="2000-01-01",freq="U")])) #
would like to transfer state from ts to test
test.__setstate__(ts.__getstate__())
# hm, seems to have gone well?
print(repr(test))

# ---------------------

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\scikits\timeseries\tseries.py", line
527, in __repr__
    timestr = str(self.dates)
  File
"C:\Python25\lib\site-packages\numpy-1.0.5.dev4749.0013-py2.5-win32.egg\numpy\core\numeric.py",
line 499, in array_str
    return array2string(a, max_line_width, precision, suppress_small, ' ',
"", str)
  File
"C:\Python25\lib\site-packages\numpy-1.0.5.dev4749.0013-py2.5-win32.egg\numpy\core\arrayprint.py",
line 240, in array2string
    separator, prefix)
  File
"C:\Python25\lib\site-packages\numpy-1.0.5.dev4749.0013-py2.5-win32.egg\numpy\core\arrayprint.py",
line 177, in _array2string
    _summaryEdgeItems, summary_insert)[:-1]
  File
"C:\Python25\lib\site-packages\numpy-1.0.5.dev4749.0013-py2.5-win32.egg\numpy\core\arrayprint.py",
line 286, in _formatArray
    word = format_function(a[-1])
  File "c:\python25\lib\site-packages\scikits\timeseries\tdates.py", line
219, in __getitem__
    unsorted = self._unsorted[indx]
IndexError: index out of bounds

# ---------------------

Tracing through with pdb showed that while the _data attribute is set
nicely, something seems to go wrong with _dates, which are turned into
None.  I am continuing up the stack with DateArray.__setstate__, but I
figure this is a reasonable time to ask for help.

I am using an approximatley month-old version of numpy 1.0.5 and today's
version of scikits.TimeSeries.

Thanks for taking a look!

Pijus





More information about the SciPy-user mailing list