[Numpy-discussion] genloadtxt question
Ryan May
rmay31@gmail....
Tue Feb 3 11:27:19 CST 2009
Pierre GM wrote:
> 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...
Thanks for the quick patch! And yeah, I can't think of any better behavior. It's
actually what I ended up doing in my conversion function, so, if nothing else,
it removes the user from having to write that kind of boilerplate code.
Thanks,
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
More information about the Numpy-discussion
mailing list