Skip to content

usecols is not respected when the file is empty #12493

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
VelizarVESSELINOV opened this issue Feb 29, 2016 · 4 comments
Closed

usecols is not respected when the file is empty #12493

VelizarVESSELINOV opened this issue Feb 29, 2016 · 4 comments
Labels
Bug IO CSV read_csv, to_csv
Milestone

Comments

@VelizarVESSELINOV
Copy link

xref #9755

If the file is empty, it is logical to compensate with extra columns.

Code Sample, a copy-pastable example if possible

"""Example of Pandas bug."""
from pandas import read_csv

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

name_list = ['Dummy', 'X', 'Dummy_2']
s = StringIO(',,')

df = read_csv(s, names=name_list, usecols=name_list[1:2], header=None)

print(list(df))

s = StringIO('')

df = read_csv(s, names=name_list, usecols=name_list[1:2], header=None)

print(list(df))

Expected Output

Current output:

['X']
['Dummy', 'X', 'Dummy_2']

Expected output:

['X']
['X']

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.17.1
nose: None
pip: 7.1.2
setuptools: 18.3.2
Cython: None
numpy: 1.10.1
scipy: 0.16.1
statsmodels: None
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: 2.3.2
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: 2.8
None

@VelizarVESSELINOV VelizarVESSELINOV changed the title usecols not respected when the file is empty usecols is not respected when the file is empty Feb 29, 2016
@jreback
Copy link
Contributor

jreback commented Feb 29, 2016

I agree, since the following is true. IOW an empty with names only produces an empty frame with the names; usecols just sub-selects.

In [19]: read_csv(StringIO(''), names=name_list, header=None)
Out[19]: 
Empty DataFrame
Columns: [Dummy, X, Dummy_2]
Index: []

@jreback jreback added this to the Next Major Release milestone Feb 29, 2016
@gfyoung
Copy link
Member

gfyoung commented Mar 2, 2016

FYI, if you try running that using engine='python', you get a StopIteration error when s = StringIO(''). Is that a bug as well?

@gfyoung
Copy link
Member

gfyoung commented Mar 2, 2016

I'll answer my own question: yes. If the C engine can do it, the Python one should be able to do it as well.

@jreback jreback modified the milestones: 0.18.1, Next Major Release Mar 8, 2016
@VelizarVESSELINOV
Copy link
Author

Thanks, much appreciated :)

gfyoung added a commit to forking-repos/pandas that referenced this issue Apr 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants