Skip to content
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

read_excel allows invalid kwargs #12507

Closed
zduey opened this issue Mar 2, 2016 · 2 comments
Closed

read_excel allows invalid kwargs #12507

zduey opened this issue Mar 2, 2016 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request IO Excel read_excel, to_excel

Comments

@zduey
Copy link

zduey commented Mar 2, 2016

Code Sample, a copy-pastable example if possible

import pandas as pd
pd.show_versions()
df = pd.DataFrame({'a':['01','02','03','04'], 'b':[5,6,7,8]})
df
df.dtypes
df.to_excel('tmp.xlsx')
df.to_csv('tmp.csv')

# Load without specifying dtypes or converter
loaded_df1 = pd.read_excel('tmp.xlsx')
loaded_df1
loaded_df1.dtypes

# Load specifying dtypes
loaded_df2 = pd.read_excel('tmp.xlsx',dtypes={'a':str,'b':int})
loaded_df2
loaded_df2.dtypes # Note that column 'a' is still of type int

# Load specifying converters
loaded_df3 = pd.read_excel('tmp.xlsx',dtypes={'a':str,'b':int})
loaded_df3
loaded_df3.dtypes # Note that column 'a' is now a string, as anticipated

# Load specifying an invalid kwarg
loaded_df4 = pd.read_excel('tmp.xlsx', invalid_kwarg=['foo','bar'])

# Load using read_csv with an invalid kwarg (should raise a TypeError)
loaded_df5 = pd.read_csv('tmp.csv', invalid_kwarg=['foo','bar'])

Expected Output

This issue is related to #8212. The dtypes kwarg is not documented as an available kwarg for the read_excel documentation. However, it also does not raise an error as an invalid kwarg if specified. When used, it appears to be ignored, but it seems that raising an error would be more helpful to the user. I know that the converters kwarg should be used instead, but this isn't obvious if you are used to read_csv and read_table, which both rely on the dtypes kwarg. More broadly, it seems like read_excel allows for any kwarg, unlike read_csv or read_table.

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-51-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: 8.0.3
setuptools: 20.1.1
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.17.0
statsmodels: 0.6.1
IPython: 4.0.2
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.6
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.2
lxml: 3.5.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
Jinja2: None

@sinhrks
Copy link
Member

sinhrks commented Mar 2, 2016

Thanks for the report. I agree all kwds should be explicit like read_csv. PR is appreciated.

@sinhrks sinhrks added Docs IO Excel read_excel, to_excel and removed Docs labels Mar 2, 2016
@jreback
Copy link
Contributor

jreback commented Mar 2, 2016

this is a dupe of #11544, currently with an open PR of #12051

@jreback jreback closed this as completed Mar 2, 2016
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Mar 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

3 participants