-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
read_csv(compression='gzip') fails while reading compressed file with tf.gfile.GFile in Python 2 #16241
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
Can you try with master? I think this may have been fixed by #16150 |
Tested with master, it is still failing with the same error message. pandas: 0.21.0.dev+8.gd50f981d7 |
At a glance, it looks like In [28]: type(g)
Out[28]: tensorflow.python.platform.gfile.GFile
In [29]: g.seek?
Signature: g.seek(position)
Docstring: Seeks to the position in the file.
File: ~/Envs/py27/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py
Type: instancemethod
|
@TomAugspurger could you please comment on the related issue on Tensorflow? They are asking questions about pandas which I have no means to comment on. |
Sure, before I do though can you run this code and post your trackeback? import pandas as pd
import numpy as np
import tensorflow as tf
df = pd.DataFrame(np.random.randn(10, 2))
df.to_csv("foo.csv.gz", compression="gzip")
pd.read_csv("foo.csv.gz", compression="gzip")
with tf.gfile.GFile("foo.csv.gz") as gf:
pd.read_csv(gf, compression="gzip") I get Traceback (most recent call last):
File "bug.py", line 11, in <module>
pd.read_csv(gf, compression="gzip")
File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/pandas/pandas/io/parsers.py", line 655, in parser_f
return _read(filepath_or_buffer, kwds)
File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/pandas/pandas/io/parsers.py", line 405, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/pandas/pandas/io/parsers.py", line 762, in __init__
self._make_engine(self.engine)
File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/pandas/pandas/io/parsers.py", line 966, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/pandas/pandas/io/parsers.py", line 1582, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 562, in pandas._libs.parsers.TextReader.__cinit__ (pandas/_libs/parsers.c:6175)
File "pandas/_libs/parsers.pyx", line 751, in pandas._libs.parsers.TextReader._get_header (pandas/_libs/parsers.c:9268)
File "pandas/_libs/parsers.pyx", line 953, in pandas._libs.parsers.TextReader._tokenize_rows (pandas/_libs/parsers.c:11755)
File "pandas/_libs/parsers.pyx", line 2173, in pandas._libs.parsers.raise_parser_error (pandas/_libs/parsers.c:28589)
TypeError: seek() takes exactly 2 arguments (3 given) which is different than the original issue (i'm a bit ahead of 0.20.1 on my python 2 environment). |
With pandas 0.19.2 + Tensorflow 1.0.0, I got this:
With pandas 0.19.2 + Tensorflow 1.1.0 (which was just released), I got a similar trace:
|
Ok, that's the difference, I was using tensorflow 1.1.0 |
Closing as it was a tensorflow bug: tensorflow/tensorflow#9806 |
Code Sample, a copy-pastable example if possible
Sample (1)
Sample (2)
Problem description
I'm converting some code to run on Google Cloud, and in the process I'm changing the way my datasets are read. I started using tf.gfile.GFile implementation from Tensorflow, as it is portable and can read both local files and files from storage buckets.
Also in the process I'm changing my code to work with Python 2 instead of Python 3.
Not sure if it is a bug in Pandas or Tensorflow code, but this issue seems similar to #14222, so I'm opening an issue here first.
To reproduce, create two files: test.csv and test.csv.gz locally. Run both samples in python 2. The sample (1) works fine, but sample (2) crashes with an error: "AttributeError: 'NoneType' object has no attribute 'Tell'"
Strangely, both samples work fine in python 3. I'm using the same library versions in python 2 and 3: pandas 0.19.2 and tensorflow 1.0.
Expected Output
Both samples should work in python 2.
Output of
pd.show_versions()
pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 32.1.0
Cython: None
numpy: 1.12.0
scipy: 0.19.0
statsmodels: None
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.10.3
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: