Skip to content

Commit a57c45e

Browse files
CLN: Cleanup code according to code checks
Co-Authored-By: Dacops <[email protected]>
1 parent cf75c28 commit a57c45e

File tree

8 files changed

+13
-12
lines changed

8 files changed

+13
-12
lines changed

doc/source/whatsnew/v3.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Other enhancements
3939
- Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`)
4040
- :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`)
4141
- :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`)
42+
- :func:`DataFrame.to_excel` now supports writing notes to an excel files via :meth:`Styler.set_tooltips` (:issue:`58070`)
43+
- :func:`read_excel` now supports reading notes from an excel file (:issue:`58070`)
4244
- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`Series.corr` (:issue:`9490`)
4345
- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`)
4446
- :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`)

pandas/core/generic.py

-2
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,6 @@ def _repr_data_resource_(self):
21312131
Arbitrary keyword arguments passed to excel engine.
21322132
"""
21332133
),
2134-
extra_examples="",
21352134
)
21362135
def to_excel(
21372136
self,
@@ -2263,7 +2262,6 @@ def to_excel(
22632262
automatically chosen depending on the file extension):
22642263
22652264
>>> df1.to_excel("output1.xlsx", engine="xlsxwriter") # doctest: +SKIP
2266-
{extra_examples}
22672265
"""
22682266
if engine_kwargs is None:
22692267
engine_kwargs = {}

pandas/io/excel/_base.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
engine_kwargs : dict, optional
282282
Arbitrary keyword arguments passed to excel engine.
283283
284-
notes: DataFrame, default None
284+
notes : DataFrame, default None
285285
A DataFrame to hold the notes extracted from the Excel file.
286286
287287
Returns
@@ -369,6 +369,10 @@
369369
``set_tooltips(notes)`` method of ``Styler.to_excel``, like in
370370
the example below:
371371
372+
>>> df = pd.DataFrame(
373+
... [[1, 100, 200], [2, 200, 300], [3, 300, 400]],
374+
... ) # doctest: +SKIP
375+
372376
>>> notes = pd.DataFrame(
373377
... [["note 1", "note 2"], ["", "note 4"], ["note 5", ""]],
374378
... ) # doctest: +SKIP
@@ -1254,11 +1258,11 @@ def book(self) -> _WorkbookT:
12541258
def _write_cells(
12551259
self,
12561260
cells,
1257-
notes,
12581261
sheet_name: str | None = None,
12591262
startrow: int = 0,
12601263
startcol: int = 0,
12611264
freeze_panes: tuple[int, int] | None = None,
1265+
notes: DataFrame | None = None,
12621266
) -> None:
12631267
"""
12641268
Write given formatted cells into Excel an excel sheet
@@ -1788,6 +1792,8 @@ def parse(
17881792
DataFrame.
17891793
17901794
.. versionadded:: 2.0
1795+
notes : DataFrame, default None
1796+
A DataFrame to hold the notes extracted from the Excel file.
17911797
**kwds : dict, optional
17921798
Arbitrary keyword arguments passed to excel engine.
17931799

pandas/io/excel/_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def _write_cells(
539539
for k, v in style_kwargs.items():
540540
setattr(xcell, k, v)
541541

542-
if notes is None:
542+
if notes is None or notes_col is None:
543543
return
544544

545545
for row_idx, (_, row) in enumerate(notes.iterrows()):

pandas/io/excel/_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def _write_cells(
290290
notes_col = startcol + cell.col
291291
wks.write(startrow + cell.row, startcol + cell.col, val, style)
292292

293-
if notes is None:
293+
if notes is None or notes_col is None:
294294
return
295295

296296
for row_idx, (_, row) in enumerate(notes.iterrows()):

pandas/tests/io/excel/test_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,5 +436,5 @@ def test_read_notes_from_xlsx_files(datapath, ext):
436436
expected = DataFrame([["note 1", "note 2"], ["", "note 4"], ["note 5", ""]])
437437
result = DataFrame()
438438
pd.read_excel(path, engine="openpyxl", notes=result)
439-
439+
440440
tm.assert_frame_equal(result, expected)

pandas/tests/io/excel/test_xlrd.py

-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,3 @@ def test_read_notes_from_xls_files(datapath, read_ext_xlrd):
8282
pd.read_excel(path, engine="xlrd", notes=result)
8383

8484
tm.assert_frame_equal(result, expected)
85-

pandas/tests/io/excel/test_xlsxwriter.py

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
from pandas.io.excel import ExcelWriter
99

10-
import pandas as pd
11-
12-
import pandas._testing as tm
13-
1410
xlsxwriter = pytest.importorskip("xlsxwriter")
1511

1612

0 commit comments

Comments
 (0)