[SciPy-user] __setstate__ of TimeSeries subclass

Pijus Virketis pijus at virketis.com
Thu Apr 24 18:36:29 EDT 2008


Pierre,

I suspected that would be the first question. What's really going on is that
I am building my subclass via multiple inheritance. As is the case with most
vanilla Python, the other superclass is instantiated only with a non-trivial
__init__, and I would like to be able to do the same "downstream" as well. I
am trying to put all of the heavy lifting into __init__, and have a __new__
that is just a step above "pass". It won't come as a big surprise to me if I
learn here that this is anywhere between ill-advised and totally dumb. ;)

class PlainSuperclass(object):
    def __init__(self, x):
        self.x = x

class Test(TimeSeries, PlainSuperclass):

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

    def __init__(self, data, dates, x):

        # set the actual state of the time series
        ts = time_series(data, dates)
        self.__setstate__(ts.__getstate__())

        # state of PlainSuperclass is added naturally
        PlainSuperclass.__init__(self, x)

# again, the real goal is to be able to subclass without knowing that we had
# to deal with a serious __new__ method upstream at all

# hypothetical
class PlainSubclass(Test):

    def __init__(self, data, dates, x, foo):
        Test.__init__(self, data, dates, x)
        self.foo = foo

Thanks again,

-P

Pierre GM said:
> On Thursday 24 April 2008 16:51:04 Pijus Virketis wrote:
>> Hi,
>>
>> I am trying to get the __setstate__ method working on a subclass of
>> scikits.TimeSeries.
>
> Pijus,
> I gonna investigate, but I'm not sure I understand what you're trying to
> do.
> Basically, __setstate__ and __getstate__ are not to be used by themselves,
> but by the _tsreconstruct functionh for pickling/unpickling.
> What's your goal ?
>





More information about the SciPy-User mailing list