File: 2p1_openpyxl_errors.patch

package info (click to toggle)
pandas 2.2.3%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,784 kB
  • sloc: python: 422,228; ansic: 9,190; sh: 270; xml: 102; makefile: 83
file content (34 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Description: Fix test failures when xlsxwriter is not installed

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: no

--- a/pandas/tests/io/excel/test_openpyxl.py
+++ b/pandas/tests/io/excel/test_openpyxl.py
@@ -124,13 +124,14 @@ def test_engine_kwargs_append_invalid(ex
                 DataFrame(["good"]).to_excel(writer, sheet_name="Sheet2")
 
 
+@td.skip_if_no("xlsxwriter")
 @pytest.mark.parametrize("data_only, expected", [(True, 0), (False, "=1+1")])
 def test_engine_kwargs_append_data_only(ext, data_only, expected):
     # GH 43445
     # tests whether the data_only engine_kwarg actually works well for
     # openpyxl's load_workbook
     with tm.ensure_clean(ext) as f:
-        DataFrame(["=1+1"]).to_excel(f)
+        DataFrame(["=1+1"]).to_excel(f, engine="xlsxwriter") # with openpyxl here, data_only=True gives None/np.nan not 0
         with ExcelWriter(
             f, engine="openpyxl", mode="a", engine_kwargs={"data_only": data_only}
         ) as writer:
--- a/pandas/tests/io/excel/test_writers.py
+++ b/pandas/tests/io/excel/test_writers.py
@@ -1420,6 +1420,8 @@ class TestExcelWriterEngineTests:
                     assert isinstance(writer, _XlsxWriter)
                 else:
                     assert isinstance(writer, klass)
+                    # openpyxl raises on closing if no sheets are written
+                    DataFrame().to_excel(writer, sheet_name="Sheet1")
 
     def test_ExcelWriter_dispatch_raises(self):
         with pytest.raises(ValueError, match="No engine"):