Skip to content

TST: read_csv with chunksize set returns empty DataFrame Instead of TextFileReader #14867

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

Closed
craymichael opened this issue Dec 12, 2016 · 1 comment · Fixed by #14920
Closed
Labels
IO CSV read_csv, to_csv Testing pandas testing functions or related to the test suite
Milestone

Comments

@craymichael
Copy link

Code Sample

import pandas as pd

# data.csv is an empty file
df = pd.read_csv('data.csv', chunksize=20, header=None, names=['a', 'b', 'c'])

Problem description

read_csv returns an empty DataFrame instead of a pandas.io.parsers.TextFileReader object when the above code is run. While this isn't a big issue, it is unexpected and the only way to tell the file is empty (through Pandas) is to check if a DataFrame was returned by read_csv. It would make more sense if None was returned instead, or the TextFileReader.

Expected Output

pandas.io.parsers.TextFileReader object

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-47-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 9.0.1
setuptools: 25.1.1
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Dec 12, 2016

in master

In [1]: pd.read_csv(StringIO(), chunksize=20, header=None, names=['a', 'b', 'c'])
Out[1]: <pandas.io.parsers.TextFileReader at 0x870fa20>

In [2]: !echo "">data.csv

In [3]: pd.read_csv('data.csv', chunksize=20, header=None, names=['a', 'b', 'c'])
Out[3]: <pandas.io.parsers.TextFileReader at 0x86ee5c0>

suppose we could have some explict tests for this

@jreback jreback added IO CSV read_csv, to_csv Difficulty Novice Testing pandas testing functions or related to the test suite labels Dec 12, 2016
@jreback jreback added this to the Next Major Release milestone Dec 12, 2016
@jreback jreback changed the title read_csv with chunksize set returns empty DataFrame Instead of TextFileReader TST: read_csv with chunksize set returns empty DataFrame Instead of TextFileReader Dec 12, 2016
jeffcarey added a commit to jeffcarey/pandas that referenced this issue Dec 19, 2016
jeffcarey added a commit to jeffcarey/pandas that referenced this issue Dec 20, 2016
Fixed flake8 issues

Added blank csv file

Removing unneeded test
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 20, 2016
jreback pushed a commit that referenced this issue Dec 20, 2016
Fixed flake8 issues

Added blank csv file

Removing unneeded test
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
Fixed flake8 issues

Added blank csv file

Removing unneeded test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants