Skip to content

read_excel allows invalid kwargs #12507

Closed
@zduey

Description

@zduey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestIO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions