Skip to content

BUG : Add Deprecation FutureWarning for parse function call #51331

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
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ I/O
- Bug in :meth:`DataFrame.to_dict` not converting ``NA`` to ``None`` (:issue:`50795`)
- Bug in :meth:`DataFrame.to_json` where it would segfault when failing to encode a string (:issue:`50307`)
- Bug in :func:`read_xml` where file-like objects failed when iterparse is used (:issue:`50641`)
- Bug in :func:`read_excel` where passing invalid argument name ``headers`` to :meth:`parse` doesn't raise error (:issue:`50953`)

Period
^^^^^^
Expand Down
40 changes: 40 additions & 0 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
cast,
overload,
)
import warnings
import zipfile

from pandas._config import (
Expand All @@ -47,6 +48,7 @@
Appender,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_bool,
Expand Down Expand Up @@ -1553,11 +1555,49 @@ def parse(
Equivalent to read_excel(ExcelFile, ...) See the read_excel
docstring for more info on accepted parameters.

.. deprecated:: 2.0.0
Arguments other than sheet_name by position may not work.

Returns
-------
DataFrame or dict of DataFrames
DataFrame from the passed in Excel file.
"""
arguments = list(kwds.keys())
allowed_kwargs = [
"sheet_name",
"header",
"names",
"index_col",
"usecols",
"squeeze",
"dtype",
"engine",
"converters",
"true_values",
"false_values",
"skiprows",
"nrows",
"na_values",
"keep_default_na",
"na_filter",
"verbose",
"parse_dates",
"date_parser",
"thousands",
"decimal",
"comment",
"skipfooter",
"convert_float",
]
# Check for any invalid kwargs
if [argument for argument in arguments if argument not in allowed_kwargs]:
warnings.warn(
f"{type(self).__name__}.parse is deprecated. "
"Arguments other than sheet_name by position may not work.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._reader.parse(
sheet_name=sheet_name,
header=header,
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,3 +1684,11 @@ def test_corrupt_files_closed(self, engine, read_ext):
pd.ExcelFile(file, engine=engine)
except errors:
pass

def test_read_excel_parse_warning(self, read_ext):
# GH50953
msg = "Arguments other than sheet_name by position may not work."
with tm.assert_produces_warning(FutureWarning, match=msg):
with pd.ExcelFile("test1" + read_ext) as excel:
excel.parse("Sheet1", headers=[0, 1, 2])
# invalid argument 'headers' should give warning for deprecation