pandas read_csv no longer supports file-like objects from tarfile (pandas 0.20.1) · Issue #16530 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd import tarfile
tar = tarfile.open(name="xxx.tar.bz2", mode='r') myfile = tar.extractfile('yyy.csv') # file-like object with a read() method data = pd.read_csv(myfile, sep=r'\s+')
This code generates this error:
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 655, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 392, in _read
filepath_or_buffer, encoding, compression)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/common.py", line 210, in get_filepath_or_buffer
raise ValueError(msg.format(_type=type(filepath_or_buffer)))
ValueError: Invalid file path or buffer object type: <class 'tarfile.ExFileObject'>
Problem description
This code works with pandas 0.19.2 but fails with 0.20.1.
According to pandas doc for read_csv:
filepath_or_buffer : str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)
I guess the new validations are too restrictive ?