Skip to content

Commit 25cdc24

Browse files
authored
CLN: drop **kwds from pd.read_excel (#34464)
1 parent eac62cf commit 25cdc24

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

doc/source/whatsnew/v1.1.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ Backwards incompatible API changes
394394
- :meth:`Series.to_timestamp` now raises a ``TypeError`` if the axis is not a :class:`PeriodIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`)
395395
- :meth:`Series.to_period` now raises a ``TypeError`` if the axis is not a :class:`DatetimeIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`)
396396
- :func: `pandas.api.dtypes.is_string_dtype` no longer incorrectly identifies categorical series as string.
397+
- :func:`read_excel` no longer takes ``**kwds`` arguments. This means that passing in keyword ``chunksize`` now raises a ``TypeError``
398+
(previously raised a ``NotImplementedError``), while passing in keyword ``encoding`` now raises a ``TypeError`` (:issue:`34464`)
397399

398400
``MultiIndex.get_indexer`` interprets `method` argument differently
399401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

pandas/io/excel/_base.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@
198198
Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
199199
'X'...'X'. Passing in False will cause data to be overwritten if there
200200
are duplicate names in the columns.
201-
**kwds : optional
202-
Optional keyword arguments can be passed to ``TextFileReader``.
203201
204202
Returns
205203
-------
@@ -290,6 +288,7 @@ def read_excel(
290288
nrows=None,
291289
na_values=None,
292290
keep_default_na=True,
291+
na_filter=True,
293292
verbose=False,
294293
parse_dates=False,
295294
date_parser=None,
@@ -298,13 +297,8 @@ def read_excel(
298297
skipfooter=0,
299298
convert_float=True,
300299
mangle_dupe_cols=True,
301-
**kwds,
302300
):
303301

304-
for arg in ("sheet", "sheetname", "parse_cols"):
305-
if arg in kwds:
306-
raise TypeError(f"read_excel() got an unexpected keyword argument `{arg}`")
307-
308302
if not isinstance(io, ExcelFile):
309303
io = ExcelFile(io, engine=engine)
310304
elif engine and engine != io.engine:
@@ -328,6 +322,7 @@ def read_excel(
328322
nrows=nrows,
329323
na_values=na_values,
330324
keep_default_na=keep_default_na,
325+
na_filter=na_filter,
331326
verbose=verbose,
332327
parse_dates=parse_dates,
333328
date_parser=date_parser,
@@ -336,7 +331,6 @@ def read_excel(
336331
skipfooter=skipfooter,
337332
convert_float=convert_float,
338333
mangle_dupe_cols=mangle_dupe_cols,
339-
**kwds,
340334
)
341335

342336

@@ -874,11 +868,6 @@ def parse(
874868
DataFrame or dict of DataFrames
875869
DataFrame from the passed in Excel file.
876870
"""
877-
if "chunksize" in kwds:
878-
raise NotImplementedError(
879-
"chunksize keyword of read_excel is not implemented"
880-
)
881-
882871
return self._reader.parse(
883872
sheet_name=sheet_name,
884873
header=header,

pandas/tests/io/excel/test_readers.py

-17
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,6 @@ def test_read_excel_bool_header_arg(self, read_ext):
897897
with pytest.raises(TypeError, match=msg):
898898
pd.read_excel("test1" + read_ext, header=arg)
899899

900-
def test_read_excel_chunksize(self, read_ext):
901-
# GH 8011
902-
msg = "chunksize keyword of read_excel is not implemented"
903-
with pytest.raises(NotImplementedError, match=msg):
904-
pd.read_excel("test1" + read_ext, chunksize=100)
905-
906900
def test_read_excel_skiprows_list(self, read_ext):
907901
# GH 4903
908902
if pd.read_excel.keywords["engine"] == "pyxlsb":
@@ -1048,17 +1042,6 @@ def test_excel_passes_na_filter(self, read_ext, na_filter):
10481042
expected = DataFrame(expected, columns=["Test"])
10491043
tm.assert_frame_equal(parsed, expected)
10501044

1051-
@pytest.mark.parametrize("arg", ["sheet", "sheetname", "parse_cols"])
1052-
@td.check_file_leaks
1053-
def test_unexpected_kwargs_raises(self, read_ext, arg):
1054-
# gh-17964
1055-
kwarg = {arg: "Sheet1"}
1056-
msg = fr"unexpected keyword argument `{arg}`"
1057-
1058-
with pd.ExcelFile("test1" + read_ext) as excel:
1059-
with pytest.raises(TypeError, match=msg):
1060-
pd.read_excel(excel, **kwarg)
1061-
10621045
def test_excel_table_sheet_by_index(self, read_ext, df_ref):
10631046
# For some reason pd.read_excel has no attribute 'keywords' here.
10641047
# Skipping based on read_ext instead.

pandas/tests/io/excel/test_writers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,7 @@ def test_to_excel_output_encoding(self, ext):
836836

837837
with tm.ensure_clean("__tmp_to_excel_float_format__." + ext) as filename:
838838
df.to_excel(filename, sheet_name="TestSheet", encoding="utf8")
839-
result = pd.read_excel(
840-
filename, sheet_name="TestSheet", encoding="utf8", index_col=0
841-
)
839+
result = pd.read_excel(filename, sheet_name="TestSheet", index_col=0)
842840
tm.assert_frame_equal(result, df)
843841

844842
def test_to_excel_unicode_filename(self, ext, path):

0 commit comments

Comments
 (0)