[SciPy-User] Error calling mov_max() on scikits.timeseries object
David Mrva
david.mrva at isamfunds.com
Thu Jul 1 06:12:56 EDT 2010
Hi Pierre,
Many thanks for your reply. It clarified the observed behaviour considerably.
I use:
>>> scikits.timeseries.__version__
'0.91.3'
>>> numpy.__version__
'1.3.0'
With Python 2.6. Both libraries came with PythonXY.
One suggestion: The doc for the 'tsfromtxt' function talks about structured dtype. A link to numpy's documentation describing the syntax and purpose would have been very useful. Similarly, a mention of the fact that the moving window functions do not accept masked arrays with structured dtype would have set the expectations right.
Many thanks,
David
-----Original Message-----
From: scipy-user-bounces at scipy.org [mailto:scipy-user-bounces at scipy.org] On Behalf Of Pierre GM
Sent: 30 June 2010 18:29
To: SciPy Users List
Subject: Re: [SciPy-User] Error calling mov_max() on scikits.timeseries object
On Jun 30, 2010, at 8:02 AM, David Mrva wrote:
> Hello All,
>
> As a new user to scikits.timeseries, I started with a simple piece of code: read a one column timeseries data from a CSV file and find moving maxima.
>
> How should I correctly use the mov_max() function with a timeseries object?
>
> When I call the mov_max() function, I keep getting an exception:
>
> >>> import numpy as np
> >>> import scikits.timeseries as ts
> >>> import scikits.timeseries.lib.moving_funcs as mf
> >>> b=ts.tsfromtxt("test4.csv", delimiter=',', names='price', datecols=(0), dtype='float')
> >>> b
> timeseries([(5277.0,) (5214.0,) (5180.0,) (5092.5,)],
> dtype = [('price', '<f8')],
> dates = [737791 738156 738521 738886],
> freq = U)
>
> >>> c=mf.mov_max(b, 2)
> Traceback (most recent call last):
> File "C:\Python26\lib\site-packages\scikits\timeseries\lib\moving_funcs.py", line 228, in mov_max
> return _moving_func(data, MA_mov_max, kwargs)
> File "C:\Python26\lib\site-packages\scikits\timeseries\lib\moving_funcs.py", line 121, in _moving_func
> data = ma.fix_invalid(data)
> File "C:\Python26\lib\site-packages\numpy\ma\core.py", line 516, in fix_invalid
> invalid = np.logical_not(np.isfinite(a._data))
> AttributeError: logical_not
> >>>
>
> Where the contents of the test4.csv file is:
> 24/06/2010 09:10,5092.5
> 23/06/2010 09:10,5180
> 22/06/2010 09:10,5214
> 21/06/2010 09:10,5277
>
> Calling mov_max() on a list of numbers works fine.
The moving functions don't require that the input is a time_series (a standard ndarray or MaskedArray works frine), but you can't use a series w/ a structured dtype (that is, w/ named fields, like the one you have). Instead, you should use
>>> c=mf.mov_max(b['price'], 2)
I'm a tad surprised by the exception you're getting. Which version of timeseries/numpy are you using ? Mine give a
NotImplementedError: Not implemented for this type
which is far more explanatory.
_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list