From 0eee20f9b3b2085c4004cb47732f9cc921ca3770 Mon Sep 17 00:00:00 2001 From: Michael Sarrazin Date: Mon, 6 Sep 2021 23:01:37 +0200 Subject: [PATCH 1/3] DOC: Modify pandas.ExcelWriter default engine in docstring (#43359) * engine for xlsx : xlsxwriter instead of openpyxl * correction to pass the doctest --- pandas/io/excel/_base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 52d1e1c83d3e6..97244f0faf226 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -647,7 +647,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): """ Class for writing DataFrame objects into excel sheets. - Default is to use xlwt for xls, openpyxl for xlsx, odf for ods. + Default is to use xlwt for xls, xlsxwriter for xlsx, odf for ods. See DataFrame.to_excel for typical usage. The writer should be used as a context manager. Otherwise, call `close()` to save @@ -721,14 +721,14 @@ class ExcelWriter(metaclass=abc.ABCMeta): Default usage: >>> df = pd.DataFrame([["ABC", "XYZ"]], columns=["Foo", "Bar"]) - >>> with ExcelWriter("path_to_file.xlsx") as writer: + >>> with pd.ExcelWriter("path_to_file.xlsx") as writer: ... df.to_excel(writer) To write to separate sheets in a single file: >>> df1 = pd.DataFrame([["AAA", "BBB"]], columns=["Spam", "Egg"]) >>> df2 = pd.DataFrame([["ABC", "XYZ"]], columns=["Foo", "Bar"]) - >>> with ExcelWriter("path_to_file.xlsx") as writer: + >>> with pd.ExcelWriter("path_to_file.xlsx") as writer: ... df1.to_excel(writer, sheet_name="Sheet1") ... df2.to_excel(writer, sheet_name="Sheet2") @@ -743,7 +743,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): ... index=["Date", "Datetime"], ... columns=["X", "Y"], ... ) - >>> with ExcelWriter( + >>> with pd.ExcelWriter( ... "path_to_file.xlsx", ... date_format="YYYY-MM-DD", ... datetime_format="YYYY-MM-DD HH:MM:SS" @@ -752,7 +752,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): You can also append to an existing Excel file: - >>> with ExcelWriter("path_to_file.xlsx", mode="a", engine="openpyxl") as writer: + >>> with pd.ExcelWriter("path_to_file.xlsx", mode="a", engine="openpyxl") as writer: ... df.to_excel(writer, sheet_name="Sheet3") You can store Excel file in RAM: From f2889e53360cf66da432a0995f9bc3886e586972 Mon Sep 17 00:00:00 2001 From: Michael Sarrazin Date: Sun, 12 Sep 2021 11:03:44 +0200 Subject: [PATCH 2/3] DOC: Modify pandas.ExcelWriter default engine in docstring (#43359) Correction after after pull review * engine for xlsx : xlsxwriter instead of openpyxl * correction to pass the doctest --- pandas/io/excel/_base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 97244f0faf226..d1aafd4ad0a35 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -647,7 +647,10 @@ class ExcelWriter(metaclass=abc.ABCMeta): """ Class for writing DataFrame objects into excel sheets. - Default is to use xlwt for xls, xlsxwriter for xlsx, odf for ods. + Default is to use : + * xlwt for xls + * xlsxwriter for xlsx if xlsxwriter is installed otherwise openpyxl + * odf for ods. See DataFrame.to_excel for typical usage. The writer should be used as a context manager. Otherwise, call `close()` to save @@ -1103,7 +1106,7 @@ def inspect_excel_format( return "zip" -class ExcelFile: +jupyterclass ExcelFile: """ Class for parsing tabular excel sheets into DataFrame objects. From c1a8d333e6a98e3bbf676a9a79cbf9f53c9be032 Mon Sep 17 00:00:00 2001 From: Michael Sarrazin Date: Sun, 12 Sep 2021 12:25:30 +0200 Subject: [PATCH 3/3] DOC: Modify pandas.ExcelWriter default engine in docstring (#43359) Correction to pass test * engine for xlsx : xlsxwriter instead of openpyxl * correction to pass the doctest --- pandas/io/excel/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index d1aafd4ad0a35..489be2de7a764 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1106,7 +1106,7 @@ def inspect_excel_format( return "zip" -jupyterclass ExcelFile: +class ExcelFile: """ Class for parsing tabular excel sheets into DataFrame objects.