Skip to content

Commit 4a7994f

Browse files
committed
Documenting the enhancement for this GH issue
1 parent 5943856 commit 4a7994f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

doc/source/user_guide/io.rst

+9
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,15 @@ one can pass an :class:`~pandas.io.excel.ExcelWriter`.
37613761
37623762
.. _io.excel_writing_buffer:
37633763

3764+
When using the ``engine_kwargs`` parameter, pandas will pass these arguments to the
3765+
engine.For this, it is important to know which function pandas is using internally.
3766+
3767+
* For the engine openpyxl, pandas is using :func:`openpyxl.Workbook` to create a new sheet and :func:`openpyxl.load_workbook` to append data to an existing sheet. The openpyxl engine writes to (``.xlsx``) and (``.xlsm``) files.
3768+
3769+
* For the engine xlsxwriter, pandas is using :func:`xlsxwriter.Workbook` to write to (``.xlsx``) files.
3770+
3771+
* For the engine odf, pandas is using :func:`odf.opendocument.OpenDocumentSpreadsheet` to write to (``.ods``) files.
3772+
37643773
Writing Excel files to memory
37653774
+++++++++++++++++++++++++++++
37663775

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Other enhancements
8787
- :meth:`DataFrame.applymap` now uses the :meth:`~api.extensions.ExtensionArray.map` method of underlying :class:`api.extensions.ExtensionArray` instances (:issue:`52219`)
8888
- :meth:`arrays.SparseArray.map` now supports ``na_action`` (:issue:`52096`).
8989
- Add dtype of categories to ``repr`` information of :class:`CategoricalDtype` (:issue:`52179`)
90+
- Adding ``engine_kwargs`` parameter to :meth:`DataFrame.to_excel` (:issue:`52368`)
9091
-
9192

9293
.. ---------------------------------------------------------------------------

pandas/tests/io/excel/test_writers.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1119,20 +1119,25 @@ def test_engine_kwargs(self, engine, path):
11191119
df = DataFrame([{"A": 1, "B": 2}, {"A": 3, "B": 4}])
11201120

11211121
msgs = {
1122-
"odf": r"OpenDocumentSpreadsheet() got an unexpected keyword argument 'foo'",
1122+
"odf": r"OpenDocumentSpreadsheet() got an unexpected keyword "
1123+
r"argument 'foo'",
11231124
"openpyxl": r"load_workbook() got an unexpected keyword argument 'foo'",
1124-
"xlsxwriter": r"Workbook.__init__() got an unexpected keyword argument 'foo'",
1125+
"xlsxwriter": r"Workbook.__init__() got an unexpected keyword "
1126+
r"argument 'foo'",
11251127
}
11261128

11271129
# Handle change in error message for openpyxl (write and append mode)
11281130
if engine == "openpyxl" and os.path.exists(path):
1129-
msgs["openpyxl"] = r"Workbook.__init__() got an unexpected keyword argument 'foo'"
1131+
msgs[
1132+
"openpyxl"
1133+
] = r"Workbook.__init__() got an unexpected keyword argument 'foo'"
11301134

11311135
else:
11321136
with pytest.raises(TypeError, match=re.escape(msgs[engine])):
1133-
df.to_excel(path,
1134-
engine_kwargs={"foo": "bar"},
1135-
)
1137+
df.to_excel(
1138+
path,
1139+
engine_kwargs={"foo": "bar"},
1140+
)
11361141

11371142
def test_write_lists_dict(self, path):
11381143
# see gh-8188.

0 commit comments

Comments
 (0)