diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 72f08ec90f5e8..c9ad86f44b0c4 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -275,6 +275,7 @@ Removal of prior version deprecations/changes - Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`) - Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`) - Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`) +- Enforced disallowing the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`) - Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`) - Enforced disallowing setting values with ``.loc`` using a positional slice. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`) - Enforced disallowing ``dict`` or ``set`` objects in ``suffixes`` in :func:`merge` (:issue:`34810`) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 0b284fd4e9750..da55f43ec477f 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -947,12 +947,6 @@ class ExcelWriter(metaclass=abc.ABCMeta): * odswriter: ``odf.opendocument.OpenDocumentSpreadsheet(**engine_kwargs)`` .. versionadded:: 1.3.0 - **kwargs : dict, optional - Keyword arguments to be passed into the engine. - - .. deprecated:: 1.3.0 - - Use engine_kwargs instead. Notes ----- @@ -1093,17 +1087,7 @@ def __new__( storage_options: StorageOptions = None, if_sheet_exists: Literal["error", "new", "replace", "overlay"] | None = None, engine_kwargs: dict | None = None, - **kwargs, ) -> ExcelWriter: - if kwargs: - if engine_kwargs is not None: - raise ValueError("Cannot use both engine_kwargs and **kwargs") - warnings.warn( - "Use of **kwargs is deprecated, use engine_kwargs instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - # only switch class if generic(ExcelWriter) if cls is ExcelWriter: if engine is None or (isinstance(engine, str) and engine == "auto"): @@ -1235,7 +1219,6 @@ def __init__( storage_options: StorageOptions = None, if_sheet_exists: str | None = None, engine_kwargs: dict[str, Any] | None = None, - **kwargs, ) -> None: # validate that this engine can handle the extension if isinstance(path, str): diff --git a/pandas/tests/io/excel/test_odswriter.py b/pandas/tests/io/excel/test_odswriter.py index e9dad0c7fedc9..21d31ec8a7fb5 100644 --- a/pandas/tests/io/excel/test_odswriter.py +++ b/pandas/tests/io/excel/test_odswriter.py @@ -19,25 +19,6 @@ def test_write_append_mode_raises(ext): ExcelWriter(f, engine="odf", mode="a") -def test_kwargs(ext): - # GH 42286 - # GH 43445 - # test for error: OpenDocumentSpreadsheet does not accept any arguments - kwargs = {"kwarg": 1} - with tm.ensure_clean(ext) as f: - msg = re.escape("Use of **kwargs is deprecated") - error = re.escape( - "OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'" - ) - with pytest.raises( - TypeError, - match=error, - ): - with tm.assert_produces_warning(FutureWarning, match=msg): - with ExcelWriter(f, engine="odf", **kwargs) as _: - pass - - @pytest.mark.parametrize("engine_kwargs", [None, {"kwarg": 1}]) def test_engine_kwargs(ext, engine_kwargs): # GH 42286 diff --git a/pandas/tests/io/excel/test_openpyxl.py b/pandas/tests/io/excel/test_openpyxl.py index 3b122c8572751..7351629660cee 100644 --- a/pandas/tests/io/excel/test_openpyxl.py +++ b/pandas/tests/io/excel/test_openpyxl.py @@ -86,19 +86,6 @@ def test_write_cells_merge_styled(ext): assert xcell_a2.font == openpyxl_sty_merged -@pytest.mark.parametrize("iso_dates", [True, False]) -def test_kwargs(ext, iso_dates): - # GH 42286 GH 43445 - kwargs = {"iso_dates": iso_dates} - with tm.ensure_clean(ext) as f: - msg = re.escape("Use of **kwargs is deprecated") - with tm.assert_produces_warning(FutureWarning, match=msg): - with ExcelWriter(f, engine="openpyxl", **kwargs) as writer: - assert writer.book.iso_dates == iso_dates - # ExcelWriter won't allow us to close without writing something - DataFrame().to_excel(writer) - - @pytest.mark.parametrize("iso_dates", [True, False]) def test_engine_kwargs_write(ext, iso_dates): # GH 42286 GH 43445 diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 307f8b7a7798f..5efdde1392123 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1337,21 +1337,6 @@ def assert_called_and_reset(cls): df.to_excel(filepath, engine="dummy") DummyClass.assert_called_and_reset() - @pytest.mark.parametrize( - "ext", - [ - pytest.param(".xlsx", marks=td.skip_if_no("xlsxwriter")), - pytest.param(".xlsx", marks=td.skip_if_no("openpyxl")), - pytest.param(".ods", marks=td.skip_if_no("odf")), - ], - ) - def test_engine_kwargs_and_kwargs_raises(self, ext): - # GH 40430 - msg = re.escape("Cannot use both engine_kwargs and **kwargs") - with pytest.raises(ValueError, match=msg): - with ExcelWriter("", engine_kwargs={"a": 1}, b=2): - pass - @td.skip_if_no("xlrd") @td.skip_if_no("openpyxl") diff --git a/pandas/tests/io/excel/test_xlsxwriter.py b/pandas/tests/io/excel/test_xlsxwriter.py index 82d47a13aefbc..477d3b05c0a74 100644 --- a/pandas/tests/io/excel/test_xlsxwriter.py +++ b/pandas/tests/io/excel/test_xlsxwriter.py @@ -1,5 +1,4 @@ import contextlib -import re import warnings import pytest @@ -65,17 +64,6 @@ def test_write_append_mode_raises(ext): ExcelWriter(f, engine="xlsxwriter", mode="a") -@pytest.mark.parametrize("nan_inf_to_errors", [True, False]) -def test_kwargs(ext, nan_inf_to_errors): - # GH 42286 - kwargs = {"options": {"nan_inf_to_errors": nan_inf_to_errors}} - with tm.ensure_clean(ext) as f: - msg = re.escape("Use of **kwargs is deprecated") - with tm.assert_produces_warning(FutureWarning, match=msg): - with ExcelWriter(f, engine="xlsxwriter", **kwargs) as writer: - assert writer.book.nan_inf_to_errors == nan_inf_to_errors - - @pytest.mark.parametrize("nan_inf_to_errors", [True, False]) def test_engine_kwargs(ext, nan_inf_to_errors): # GH 42286