-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: python 3 compression and read_fwf #3963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Doing a bit of digging around, looks like it's a unicode thing. The error is coming here, line 1919 in pandas/build/lib.macosx-10.8-x86_64-3.3/pandas/io/parsers.py: def next(self):
line = next(self.f)
# Note: 'colspecs' is a sequence of half-open intervals.
return [line[fromm:to].strip(self.filler or ' ')
for (fromm, to) in self.colspecs] here, ipdb> line
b'1111111111\n' I'm not sure what the preferred way of dealing with this is, but ipdb> line.decode('utf-8')[fromm:to].strip(' ')
'11111' works. |
should probably be import pandas.core.common as com
com.pprint_thing(line[fromm:to]).strip(self.filler or ' ') |
basically, the problem is that you can't mix In [12]: b'abcd'.strip('')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-e487f65c9b72> in <module>()
----> 1 b'abcd'.strip('')
TypeError: Type str doesn't support the buffer API
In [13]: # Whereas it works with bytes
In [14]: b'adbc'.strip(b'')
Out[14]: b'adbc' |
I'm reopening, since after staring at #4784 for a bit I think it's (and my +1 of it) wrong. The use of next(f) when f is a BytesIO object seem dodgy, An example to illustrate some of this:
I think |
@y-p Two options:
Either way would work - (1) is probably more explicit though. If |
So you did, didn't see it earlier. I would be fine with correct code that only works on 3.3 and raising an error (or just blowing up) otherwise. |
Getting a
TypeError: Type str doesn't support the buffer API
when usingread_fwf
on a compressed file with python 3 only; works in python 2.7Example:
with a file
fwf.bug.txt
likeVersions:
python3:
0.11.1.dev-4d06037
should be most recentpython2:
0.11.1.dev-3ebfef9
I can paste the full traceback if you'd like.
The text was updated successfully, but these errors were encountered: