Skip to content

Commit 0045601

Browse files
CLN: Raise exceptions when trying to write notes while using unsupported engines (pandas-dev#58070)
Co-authored-by: diogomsmiranda <[email protected]>
1 parent 1bb8678 commit 0045601

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

pandas/io/excel/_odswriter.py

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
WriteExcelBuffer,
2828
)
2929

30+
from pandas.core.frame import DataFrame
31+
3032
from pandas.io.formats.excel import ExcelCell
3133

3234

@@ -99,6 +101,7 @@ def _write_cells(
99101
startrow: int = 0,
100102
startcol: int = 0,
101103
freeze_panes: tuple[int, int] | None = None,
104+
notes: DataFrame | None = None,
102105
) -> None:
103106
"""
104107
Write the frame cells using odf
@@ -110,6 +113,14 @@ def _write_cells(
110113
)
111114
from odf.text import P
112115

116+
if notes is not None:
117+
raise NotImplementedError(
118+
"""
119+
Notes are not supported by the odswriter engine,
120+
see https://github.com/mmulqueen/odswriter
121+
"""
122+
)
123+
113124
sheet_name = self._get_sheet_name(sheet_name)
114125
assert sheet_name is not None
115126

pandas/io/excel/_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,11 @@ def _convert_to_protection(cls, protection_dict):
445445
def _write_cells(
446446
self,
447447
cells,
448-
notes,
449448
sheet_name: str | None = None,
450449
startrow: int = 0,
451450
startcol: int = 0,
452451
freeze_panes: tuple[int, int] | None = None,
452+
notes: DataFrame | None = None,
453453
) -> None:
454454
from openpyxl.comments import Comment
455455

pandas/io/excel/_xlsxwriter.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
WriteExcelBuffer,
2121
)
2222

23+
from pandas.core.frame import DataFrame
24+
2325

2426
class _XlsxStyler:
2527
# Map from openpyxl-oriented styles to flatter xlsxwriter representation
@@ -241,11 +243,11 @@ def _save(self) -> None:
241243
def _write_cells(
242244
self,
243245
cells,
244-
notes,
245246
sheet_name: str | None = None,
246247
startrow: int = 0,
247248
startcol: int = 0,
248249
freeze_panes: tuple[int, int] | None = None,
250+
notes: DataFrame | None = None,
249251
) -> None:
250252
# Write the frame cells using xlsxwriter.
251253
sheet_name = self._get_sheet_name(sheet_name)

pandas/io/formats/excel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ def __init__(
553553
) -> None:
554554
self.rowcounter = 0
555555
self.na_rep = na_rep
556+
self.notes = None
556557
if not isinstance(df, DataFrame):
557-
self.notes = None
558558
if df.tooltips is not None:
559559
self.notes = df.tooltips.tt_data
560560
self.styler = df
@@ -947,11 +947,11 @@ def write(
947947
try:
948948
writer._write_cells(
949949
formatted_cells,
950-
self.notes,
951950
sheet_name,
952951
startrow=startrow,
953952
startcol=startcol,
954953
freeze_panes=freeze_panes,
954+
notes=self.notes,
955955
)
956956
finally:
957957
# make sure to close opened file handles

0 commit comments

Comments
 (0)