[Numpy-discussion] genloadtxt question

Pierre GM pgmdevlist at gmail.com
Tue Feb 3 12:17:01 EST 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