Skip to content

Commit 0408544

Browse files
authored
Unique edge case tests
1 parent ac6294b commit 0408544

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

pandas/tests/io/excel/test_xlsxwriter.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,57 @@ def test_book_and_sheets_consistent(tmp_excel):
9393
assert writer.sheets == {"test_name": sheet}
9494

9595

96+
def test_autofilter_empty_dataframe(tmp_excel):
97+
# GH 61194 - Edge case: empty DataFrame with autofilter
98+
openpyxl = pytest.importorskip("openpyxl")
99+
df = DataFrame()
100+
df.to_excel(tmp_excel, engine="xlsxwriter", autofilter=True)
101+
102+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
103+
ws = wb.active
104+
# Empty DataFrame should still set autofilter (even if range is just header)
105+
assert ws.auto_filter.ref is not None
106+
107+
108+
def test_autofilter_single_row(tmp_excel):
109+
# GH 61194 - Edge case: single row DataFrame
110+
openpyxl = pytest.importorskip("openpyxl")
111+
df = DataFrame({"A": [1], "B": [2]})
112+
df.to_excel(tmp_excel, engine="xlsxwriter", autofilter=True, index=False)
113+
114+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
115+
ws = wb.active
116+
assert ws.auto_filter.ref is not None
117+
# Should cover header + 1 row: A1:B2
118+
assert ws.auto_filter.ref == "A1:B2"
119+
120+
121+
def test_autofilter_single_column(tmp_excel):
122+
# GH 61194 - Edge case: single column DataFrame
123+
openpyxl = pytest.importorskip("openpyxl")
124+
df = DataFrame({"A": [1, 2, 3]})
125+
df.to_excel(tmp_excel, engine="xlsxwriter", autofilter=True, index=False)
126+
127+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
128+
ws = wb.active
129+
assert ws.auto_filter.ref is not None
130+
# Should cover header + 3 rows: A1:A4
131+
assert ws.auto_filter.ref == "A1:A4"
132+
133+
134+
def test_autofilter_no_header(tmp_excel):
135+
# GH 61194 - Edge case: autofilter with header=False
136+
openpyxl = pytest.importorskip("openpyxl")
137+
df = DataFrame([[1, 2], [3, 4]])
138+
df.to_excel(tmp_excel, engine="xlsxwriter", autofilter=True, header=False, index=False)
139+
140+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
141+
ws = wb.active
142+
assert ws.auto_filter.ref is not None
143+
# Without header, filter should start at first row: A1:B2
144+
assert ws.auto_filter.ref == "A1:B2"
145+
146+
96147
@xfail_autofilter
97148
def test_to_excel_autofilter_xlsxwriter(tmp_excel):
98149
openpyxl = pytest.importorskip("openpyxl")

0 commit comments

Comments
 (0)