[SciPy-User] [scikits-timeseries] Some problems with inheritance (begginer's question, long)

J. David Lee johnl@cs.wisc....
Sat Oct 2 19:25:51 CDT 2010


It looks to me like ipl.interp_masked1d is calling the constructor of
the ChromaData class. If this is the case, you'll have to make sure that
the ChromaData constructor has the same signature as the TimeSeries
constructor. You can pass `data' and `dates' as keyword arguments:

 class ChromaData(ts.TimeSeries):
    u"""Represents chromatographic timeseries data, inherits from TimeSeries."""

    def __init__(self, *args, data = None, dates = None, **kwargs):
        super(ChromaData, self).__init__(*args, **kwargs)

Just be sure that you don't have problems when `data' and `dates' are

This way when another part of the code tries to create a ChromaData
object in place of a TimeSeries object it will work properly. 


On Sun, 2010-10-03 at 02:14 +0200, Paweł Rumian wrote:
> Thank you J. David - your mail was a significant help. I've read about
> *args and *kwargs, and they indeed seem to be important in such cases.
> However I still cannot solve the problem... For me it seems that the
> function interp_masked1d from scikits.timeseries.lib.interpolate won't
> work with anything else than TimeSeries instance - or is it still me
> doing something wrong, maybe with initializing the instance of
> ChromaData?
> I'm trying to do is as simple as it could be - I stripped the whole
> ChromaData Class to single __init__ method, like this:
> class ChromaData(ts.TimeSeries):
>     u"""Represents chromatographic timeseries data, inherits from TimeSeries."""
>     def __init__(self,data,dates,*args,**kwargs):
>         super(ChromaData, self).__init__(*args,**kwargs)
> Then I create a TimeSeries instance, loading it from file
> (get_data_from_file is just a wrapper to ts.tsfromtxt), and a
> ChromaData instance:
> timeseries_instance= get_data_from_file('testdata.dat')
> chromadata_instance=
> ChromaData(timeseries_instance.data,timeseries_instance.dates)
> For certainity:
> print (timeseries_instance.__class__)
> <class 'scikits.timeseries.tseries.TimeSeries'>
> print (chromadata_instance.__class__)
> <class '__main__.ChromaData'>
> And then I run
> ipl.interp_masked1d(timeseries_instance)
> (everything is OK here)
> ipl.interp_masked1d(chromadata_instance)
> and I get:
> Traceback (most recent call last):
>   File "testcase.py", line 39, in <module>
>     ipl.interp_masked1d(chromadata_instance)
>   File "/usr/lib/python2.6/site-packages/scikits/timeseries/lib/interpolate.py",
> line 125, in interp_masked1d
>     marr = marray(marr, copy=True)
>   File "/usr/lib/python2.6/site-packages/numpy/ma/core.py", line 5491, in array
>     fill_value=fill_value, ndmin=ndmin, shrink=shrink)
> TypeError: __init__() takes at least 3 non-keyword arguments (2 given)
> The whole code can be found at: http://pastebin.com/Vd3mCr8M
> I've tried converting ChromaData instance to TimeSeries before feeding
> interp_masked1d with it, like
> ipl.interp_masked1d(ts.TimeSeries(chromadata_instance.data,
> chromadata_instance.dates), kind='linear')
> and it works, but it's just a workaround...
> Thank you for all possible help,
> Paweł
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-User mailing list