[SciPy-User] scikits.timeseries: Using dtype in tsfromtxt

Pierre GM pgmdevlist@gmail....
Tue Oct 20 20:37:11 CDT 2009


On Oct 20, 2009, at 7:44 PM, all6junk@gmail.com wrote:

Hi Chaitanya,
>
> def loadscrip(scripfile):
>     dt = np.dtype([('date', 'a8'), ('open', 'f4'), ('high', 'f4')])
>     ser = ts.tsfromtxt(scripfile, dtype=dt,
>             delimiter=',', datecols=(0), dateconverter=dconv)
>     return ser

That's part of your problem here: you should use dtype=[('open',  
'f4'), ('high', 'f4')] instead of dtype=[('date', 'a8'), ('open',  
'f4'), ('high', 'f4')]. The reason is that with your dtype, you'd ask  
for twice the date information.
Unfortunately, you also uncovered a bug (actually, a couple...),  
related to the fact that you want "f4" instead of "f8".

For the time being, if you can, just use dtype=[('open', float),  
('high', 'float)]. If you can't, then first use dtype=[('open',  
float), ('high', 'float)], then create an empty series with dtype= 
[('open', 'f4'), ('high', 'f4')] and fill it...

Sorry for the inconvenience and not being able to give you a better  
solution right now. I should be able to work on that in the next  
couple of days and keep you posted. I need to warn you that the fixes  
may not work w/ numpy 1.3.0. We'll see.

Sorry again
P.




More information about the SciPy-User mailing list