[Numpy-discussion] numpy.genfromtxt converters issue

Pierre GM pgmdevlist@gmail....
Mon Nov 15 06:36:09 CST 2010


On Nov 15, 2010, at 1:07 PM, Lluís wrote:

> Pierre GM writes:
> 
>> On Nov 14, 2010, at 9:30 PM, Lluís wrote:
> 
>>> This will work as long as 'first_values' is assured to always contain
>>> valid data and as long as its indexes are equivalent to those in
>>> converters (which I simply haven't checked).
> 
>> I beat you to it, actually ;)
> 
> Argh! :)

In all good spirit :)


> 
>> Check the git push I committed earlier today. I followed exactly the
>> same approach as yours (well, almost: I do check whether the first
>> line is empty (there were names) and then fall back on the default
>> testing value ('1')...
> 
> Just out of curiosity... why do you check for the length of
> 'first_line'? Now I've looked into the code, and it seems that
> 'first_values' will always contain valid contents:
>  https://github.com/numpy/numpy/blob/de4de92be21e4dda3665648ad5102b3729d4e0b0/numpy/lib/npyio.py#L1209

Valid content, not necessarily valid values: you can have column names, if you chose names=True. In that case, you wouldn't want to use these names as testing values. An easy way to catch whether the first values are names is to check the first_line: if it's '', then it was names...



More information about the NumPy-Discussion mailing list