ValueError with ts.convert of scikits.timeseries
Hello, I encountered an error working with a recarray read from a ASCII file with ts.tsfromtxt [1]. The steps were conducted: 1) read in with ts.tsfromtxt ==> recarray with data with minutely frequency 2) missing dates were filed with ts.fill_missing_dates ==> complete series 3) convert into hourly frequency with ts.convert 4) an error occurs, see below. What could be the cause for this? My recarray have the following dtypes: dtype = [('f2', '<i4'), ('f3', '<f8'), ('f4', '<f8'), ('f5', '<i4'), ('f6', '<i4'), ('f7', '<f8'), ('f8', '<f8'), ('f9', '<f8'), ('f10', '<f8'), ('f11', '<f8'), ('f12', '<f8')], Another question related to this: How do I convert the recarrays returned by ts.tsfromtxt into a ndarray? I would like to transform the recarray in a form similar to what is returned data is loaded with np.loadtxt (and then pushed in a timeseries)? I would appreciate any help. Thanks in advance, Marco ##### Traceback ##### [C:scripts/eval]|103> run dataeval.py ------------------------------------------------------------------------ --- ValueError Traceback (most recent call last) C:\scripts\eval\dataeval.py in <module>() 42 myseries_filled_min = ts.fill_missing_dates(series) 43 ---> 44 myseries_hourly_mean = ts.convert(myseries_filled_min,'H',func=np.mean) C:\Python26\lib\site-packages\scikits\timeseries\tseries.pyc in convert(series, freq, func, position, *args, **kwargs) 2003 2004 if series.ndim == 1: -> 2005 obj = _convert1d(series, freq, func, position, *args, **kwargs) 2006 elif series.ndim == 2: 2007 base = _convert1d(series[:,0], freq, func, position, *args, **kwargs) C:\Python26\lib\site-packages\scikits\timeseries\tseries.pyc in _convert1d(series, freq, func, position, *args, **kwargs) 1913 1914 cdictresult = cseries.TS_convert(data_, from_freq, to_freq, position, -> 1915 int(start_date), mask_) 1916 start_date = Date(freq=to_freq, value=cdictresult['startindex']) 1917 data_ = masked_array(cdictresult['values'], mask=cdictresult['mask']) ValueError: data type must provide an itemsize WARNING: Failure executing file: <dataeval.py> ##### [1]: http://pytseries.sourceforge.net/core.timeseries.io.html
On Mar 3, 2010, at 5:47 PM, Marco Tuckner wrote:
Hello, I encountered an error working with a recarray read from a ASCII file with ts.tsfromtxt [1].
The steps were conducted:
1) read in with ts.tsfromtxt ==> recarray with data with minutely frequency 2) missing dates were filed with ts.fill_missing_dates ==> complete series 3) convert into hourly frequency with ts.convert 4) an error occurs, see below.
What could be the cause for this?
The fact that you're using a structured array (that is, an array with named fields. a recarray is a special kind of structured array). The conversion functions don't work in that case, you have to convert field by field. In your case, I'd do something like this: * convert the first field to hours using .convert and save the reslut in a temporary array * create an empty timeseries with the same dtype as your input and the same dates as the temporary array you just created. * Loop on the fields of the input, convert them to hours and store them in the corresponding field of your new array
My recarray have the following dtypes:
dtype = [('f2', '<i4'), ('f3', '<f8'), ('f4', '<f8'), ('f5', '<i4'), ('f6', '<i4'), ('f7', '<f8'), ('f8', '<f8'), ('f9', '<f8'), ('f10', '<f8'), ('f11', '<f8'), ('f12', '<f8')],
Another question related to this: How do I convert the recarrays returned by ts.tsfromtxt into a ndarray?
Use .view(np.ndarray). Note that on top of dropping the dates, you also lose the mask. If you need the mask, use the .series attribute.
participants (2)
-
Marco Tuckner
-
Pierre GM