[Numpy-discussion] bug in genfromtxt for python 3.2

Matthew Brett matthew.brett@gmail....
Tue Mar 29 20:39:54 CDT 2011


Hi,

On Mon, Mar 28, 2011 at 11:29 PM,  <josef.pktd@gmail.com> wrote:
> numpy/lib/test_io.py    only uses StringIO in the test, no actual csv file
>
> If I give the filename than I get a  TypeError: Can't convert 'bytes'
> object to str implicitly
>
>
> from the statsmodels mailing list example
>
>>>>> data = recfromtxt(open('./star98.csv', "U"), delimiter=",", skip_header=1, dtype=float)
>> Traceback (most recent call last):
>>  File "<pyshell#30>", line 1, in <module>
>>    data = recfromtxt(open('./star98.csv', "U"), delimiter=",",
>> skip_header=1, dtype=float)
>>  File "C:\Programs\Python32\lib\site-packages\numpy\lib\npyio.py",
>> line 1633, in recfromtxt
>>    output = genfromtxt(fname, **kwargs)
>>  File "C:\Programs\Python32\lib\site-packages\numpy\lib\npyio.py",
>> line 1181, in genfromtxt
>>    first_values = split_line(first_line)
>>  File "C:\Programs\Python32\lib\site-packages\numpy\lib\_iotools.py",
>> line 206, in _delimited_splitter
>>    line = line.split(self.comments)[0].strip(asbytes(" \r\n"))
>> TypeError: Can't convert 'bytes' object to str implicitly

Is the right fix for this to open a 'filename' passed to genfromtxt,
as 'binary' (bytes)?

If so I will submit a pull request with a fix and a test,

Best,

Matthew


More information about the NumPy-Discussion mailing list