[SciPy-User] Error calling mov_max() on scikits.timeseries object

Pierre GM pgmdevlist@gmail....
Wed Jun 30 12:28:49 CDT 2010


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.




More information about the SciPy-User mailing list