Skip to content

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

Closed
@craymichael

Description

@craymichael

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO CSVread_csv, to_csvTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions