usecols is not respected when the file is empty · Issue #12493 · pandas-dev/pandas (original) (raw)
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:
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