[Numpy-discussion] genloadtxt question

Pierre GM pgmdevlist@gmail....
Tue Feb 3 11:17:01 CST 2009


On Feb 3, 2009, at 11:24 AM, Ryan May wrote:

> Pierre,
>
> Should the following work?
>
> import numpy as np
> from StringIO import StringIO
>
> converter = {'date':lambda s: datetime.strptime(s,'%Y-%m-%d %H:%M: 
> %SZ')}
> data = np.ndfromtxt(StringIO('2009-02-03 12:00:00Z,72214.0'),  
> delimiter=',',
> names=['date','stid'], dtype=None, converters=converter)

Well, yes, it should work. That's indeed a problem with the  
getsubdtype method of the converter.
The problem is that we need to estimate the datatype of the output of  
the converter. In most cases, trying to convert '0' works properly,  
not in yours however. In r6338, I force the type to object if  
converting '0' does not work. That's a patch till the next corner  
case...



More information about the Numpy-discussion mailing list