Skip to content

Commit 645b499

Browse files
authored
DEPR: Disallow kwargs in ExcelWriter (#49463)
1 parent f43d3a7 commit 645b499

File tree

6 files changed

+1
-76
lines changed

6 files changed

+1
-76
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Removal of prior version deprecations/changes
277277
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`)
278278
- Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`)
279279
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
280+
- Enforced disallowing the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
280281
- Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`)
281282
- Enforced disallowing setting values with ``.loc`` using a positional slice. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`)
282283
- Enforced disallowing ``dict`` or ``set`` objects in ``suffixes`` in :func:`merge` (:issue:`34810`)

pandas/io/excel/_base.py

-17
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,6 @@ class ExcelWriter(metaclass=abc.ABCMeta):
947947
* odswriter: ``odf.opendocument.OpenDocumentSpreadsheet(**engine_kwargs)``
948948
949949
.. versionadded:: 1.3.0
950-
**kwargs : dict, optional
951-
Keyword arguments to be passed into the engine.
952-
953-
.. deprecated:: 1.3.0
954-
955-
Use engine_kwargs instead.
956950
957951
Notes
958952
-----
@@ -1093,17 +1087,7 @@ def __new__(
10931087
storage_options: StorageOptions = None,
10941088
if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = None,
10951089
engine_kwargs: dict | None = None,
1096-
**kwargs,
10971090
) -> ExcelWriter:
1098-
if kwargs:
1099-
if engine_kwargs is not None:
1100-
raise ValueError("Cannot use both engine_kwargs and **kwargs")
1101-
warnings.warn(
1102-
"Use of **kwargs is deprecated, use engine_kwargs instead.",
1103-
FutureWarning,
1104-
stacklevel=find_stack_level(),
1105-
)
1106-
11071091
# only switch class if generic(ExcelWriter)
11081092
if cls is ExcelWriter:
11091093
if engine is None or (isinstance(engine, str) and engine == "auto"):
@@ -1235,7 +1219,6 @@ def __init__(
12351219
storage_options: StorageOptions = None,
12361220
if_sheet_exists: str | None = None,
12371221
engine_kwargs: dict[str, Any] | None = None,
1238-
**kwargs,
12391222
) -> None:
12401223
# validate that this engine can handle the extension
12411224
if isinstance(path, str):

pandas/tests/io/excel/test_odswriter.py

-19
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,6 @@ def test_write_append_mode_raises(ext):
1919
ExcelWriter(f, engine="odf", mode="a")
2020

2121

22-
def test_kwargs(ext):
23-
# GH 42286
24-
# GH 43445
25-
# test for error: OpenDocumentSpreadsheet does not accept any arguments
26-
kwargs = {"kwarg": 1}
27-
with tm.ensure_clean(ext) as f:
28-
msg = re.escape("Use of **kwargs is deprecated")
29-
error = re.escape(
30-
"OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'"
31-
)
32-
with pytest.raises(
33-
TypeError,
34-
match=error,
35-
):
36-
with tm.assert_produces_warning(FutureWarning, match=msg):
37-
with ExcelWriter(f, engine="odf", **kwargs) as _:
38-
pass
39-
40-
4122
@pytest.mark.parametrize("engine_kwargs", [None, {"kwarg": 1}])
4223
def test_engine_kwargs(ext, engine_kwargs):
4324
# GH 42286

pandas/tests/io/excel/test_openpyxl.py

-13
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,6 @@ def test_write_cells_merge_styled(ext):
8686
assert xcell_a2.font == openpyxl_sty_merged
8787

8888

89-
@pytest.mark.parametrize("iso_dates", [True, False])
90-
def test_kwargs(ext, iso_dates):
91-
# GH 42286 GH 43445
92-
kwargs = {"iso_dates": iso_dates}
93-
with tm.ensure_clean(ext) as f:
94-
msg = re.escape("Use of **kwargs is deprecated")
95-
with tm.assert_produces_warning(FutureWarning, match=msg):
96-
with ExcelWriter(f, engine="openpyxl", **kwargs) as writer:
97-
assert writer.book.iso_dates == iso_dates
98-
# ExcelWriter won't allow us to close without writing something
99-
DataFrame().to_excel(writer)
100-
101-
10289
@pytest.mark.parametrize("iso_dates", [True, False])
10390
def test_engine_kwargs_write(ext, iso_dates):
10491
# GH 42286 GH 43445

pandas/tests/io/excel/test_writers.py

-15
Original file line numberDiff line numberDiff line change
@@ -1337,21 +1337,6 @@ def assert_called_and_reset(cls):
13371337
df.to_excel(filepath, engine="dummy")
13381338
DummyClass.assert_called_and_reset()
13391339

1340-
@pytest.mark.parametrize(
1341-
"ext",
1342-
[
1343-
pytest.param(".xlsx", marks=td.skip_if_no("xlsxwriter")),
1344-
pytest.param(".xlsx", marks=td.skip_if_no("openpyxl")),
1345-
pytest.param(".ods", marks=td.skip_if_no("odf")),
1346-
],
1347-
)
1348-
def test_engine_kwargs_and_kwargs_raises(self, ext):
1349-
# GH 40430
1350-
msg = re.escape("Cannot use both engine_kwargs and **kwargs")
1351-
with pytest.raises(ValueError, match=msg):
1352-
with ExcelWriter("", engine_kwargs={"a": 1}, b=2):
1353-
pass
1354-
13551340

13561341
@td.skip_if_no("xlrd")
13571342
@td.skip_if_no("openpyxl")

pandas/tests/io/excel/test_xlsxwriter.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import re
32
import warnings
43

54
import pytest
@@ -65,17 +64,6 @@ def test_write_append_mode_raises(ext):
6564
ExcelWriter(f, engine="xlsxwriter", mode="a")
6665

6766

68-
@pytest.mark.parametrize("nan_inf_to_errors", [True, False])
69-
def test_kwargs(ext, nan_inf_to_errors):
70-
# GH 42286
71-
kwargs = {"options": {"nan_inf_to_errors": nan_inf_to_errors}}
72-
with tm.ensure_clean(ext) as f:
73-
msg = re.escape("Use of **kwargs is deprecated")
74-
with tm.assert_produces_warning(FutureWarning, match=msg):
75-
with ExcelWriter(f, engine="xlsxwriter", **kwargs) as writer:
76-
assert writer.book.nan_inf_to_errors == nan_inf_to_errors
77-
78-
7967
@pytest.mark.parametrize("nan_inf_to_errors", [True, False])
8068
def test_engine_kwargs(ext, nan_inf_to_errors):
8169
# GH 42286

0 commit comments

Comments
 (0)