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

usecols is not respected when the file is empty #12493

Closed
VelizarVESSELINOV opened this Issue Feb 29, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@VelizarVESSELINOV

VelizarVESSELINOV commented Feb 29, 2016

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 from usecols not respected when the file is empty to usecols is not respected when the file is empty Feb 29, 2016

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Feb 29, 2016

Contributor

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: []
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

This comment has been minimized.

Show comment
Hide comment
@gfyoung

gfyoung Mar 2, 2016

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@gfyoung

gfyoung Mar 2, 2016

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@VelizarVESSELINOV

VelizarVESSELINOV Mar 8, 2016

Thanks, much appreciated :)

VelizarVESSELINOV commented Mar 8, 2016

Thanks, much appreciated :)

gfyoung added a commit to gfyoung/pandas that referenced this issue Apr 12, 2016

@jreback jreback closed this in 827745d Apr 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment