timeseries.convert and structured arrays

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

timeseries.convert and structured arrays

dhirschfeld
Hi,
I ran into a problem using the convert function with a structured array (see
below) so I just wanted to check if the timeseries function convert is intended
to support structured arrays? If not are there any plans to do so? And if it
does, what am I doing wrong below??

Thanks,
Dave

dates = ts.date_array(start_date=ts.Date('D','2008-01-01'),
                      end_date=ts.Date('D','2008-12-31'))
#

data = np.array(zip(np.random.rand(366),np.random.rand(366)),
                dtype=[('field1',np.float),('field2',np.object)])
#

data = ts.time_series(data,dates)
data.convert('M')



C:\dev\bin\Python25\lib\site-packages\scikits\timeseries\tseries.pyc in
convert(series, freq, func, position, *args, **kwargs)
   1999
   2000     if series.ndim == 1:
-> 2001         obj = _convert1d(series, freq, func, position, *args, **kwargs)
   2002     elif series.ndim == 2:
   2003         base = _convert1d(series[:,0], freq, func, position, *args,
**kwargs)

C:\dev\bin\Python25\lib\site-packages\scikits\timeseries\tseries.pyc in
_convert1d(series, freq, func, position, *args, **kwargs)
   1909
   1910     cdictresult = cseries.TS_convert(data_, from_freq, to_freq, position,
-> 1911                                      int(start_date), mask_)
   1912     start_date = Date(freq=to_freq, value=cdictresult['startindex'])
   1913     data_ = masked_array(cdictresult['values'], mask=cdictresult['mask'])

ValueError: data type must provide an itemsize



_______________________________________________
SciPy-user mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: timeseries.convert and structured arrays

Pierre GM-2

On Apr 29, 2009, at 10:10 AM, Dave Hirschfeld wrote:

> Hi,
> I ran into a problem using the convert function with a structured  
> array (see
> below) so I just wanted to check if the timeseries function convert  
> is intended
> to support structured arrays?

Doesn't work yet, sorry...

> If not are there any plans to do so?

When I'll have some time working on it, yes. Sometime this summer if  
I'm lucky...

Meanwhile, you can emulate it by converting each field independently  
and repatching the result

 >>> data = ts.time_series(data,dates)

 >>> mfield1 = data['field1'].convert("M")
 >>> mdata = ts.time_series(np.empty(mfield1.shape, dtype=data.dtype),
...                 dates=mfield1.dates)
 >>> mdata['field1'] = mfield1
 >>> mdata['field2'] = data['field2'].convert("M")




> And if it
> does, what am I doing wrong below??
>
> Thanks,
> Dave
>
> dates = ts.date_array(start_date=ts.Date('D','2008-01-01'),
>                      end_date=ts.Date('D','2008-12-31'))
> #
>
> data = np.array(zip(np.random.rand(366),np.random.rand(366)),
>                dtype=[('field1',np.float),('field2',np.object)])
> #
>
> data = ts.time_series(data,dates)
> data.convert('M')
>
>
>
> C:\dev\bin\Python25\lib\site-packages\scikits\timeseries\tseries.pyc  
> in
> convert(series, freq, func, position, *args, **kwargs)
>   1999
>   2000     if series.ndim == 1:
> -> 2001         obj = _convert1d(series, freq, func, position,  
> *args, **kwargs)
>   2002     elif series.ndim == 2:
>   2003         base = _convert1d(series[:,0], freq, func, position,  
> *args,
> **kwargs)
>
> C:\dev\bin\Python25\lib\site-packages\scikits\timeseries\tseries.pyc  
> in
> _convert1d(series, freq, func, position, *args, **kwargs)
>   1909
>   1910     cdictresult = cseries.TS_convert(data_, from_freq,  
> to_freq, position,
> -> 1911                                      int(start_date), mask_)
>   1912     start_date = Date(freq=to_freq,  
> value=cdictresult['startindex'])
>   1913     data_ = masked_array(cdictresult['values'],  
> mask=cdictresult['mask'])
>
> ValueError: data type must provide an itemsize
>
>
>
> _______________________________________________
> SciPy-user mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-user mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user