Skip to content

Commit ac6294b

Browse files
authored
Unique edge case tests
1 parent 5fc8141 commit ac6294b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pandas/tests/io/excel/test_openpyxl.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,50 @@ def test_read_multiindex_header_no_index_names(datapath, ext):
519519
index=pd.MultiIndex.from_tuples([("A", "AA", "AAA"), ("A", "BB", "BBB")]),
520520
)
521521
tm.assert_frame_equal(result, expected)
522+
523+
524+
def test_autofilter_empty_dataframe(tmp_excel):
525+
# GH 61194 - Edge case: empty DataFrame with autofilter
526+
df = DataFrame()
527+
df.to_excel(tmp_excel, engine="openpyxl", autofilter=True)
528+
529+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
530+
ws = wb.active
531+
# Empty DataFrame should still set autofilter (even if range is just header)
532+
assert ws.auto_filter.ref is not None
533+
534+
535+
def test_autofilter_single_row(tmp_excel):
536+
# GH 61194 - Edge case: single row DataFrame
537+
df = DataFrame({"A": [1], "B": [2]})
538+
df.to_excel(tmp_excel, engine="openpyxl", autofilter=True, index=False)
539+
540+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
541+
ws = wb.active
542+
assert ws.auto_filter.ref is not None
543+
# Should cover header + 1 row: A1:B2
544+
assert ws.auto_filter.ref == "A1:B2"
545+
546+
547+
def test_autofilter_single_column(tmp_excel):
548+
# GH 61194 - Edge case: single column DataFrame
549+
df = DataFrame({"A": [1, 2, 3]})
550+
df.to_excel(tmp_excel, engine="openpyxl", autofilter=True, index=False)
551+
552+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
553+
ws = wb.active
554+
assert ws.auto_filter.ref is not None
555+
# Should cover header + 3 rows: A1:A4
556+
assert ws.auto_filter.ref == "A1:A4"
557+
558+
559+
def test_autofilter_no_header(tmp_excel):
560+
# GH 61194 - Edge case: autofilter with header=False
561+
df = DataFrame([[1, 2], [3, 4]])
562+
df.to_excel(tmp_excel, engine="openpyxl", autofilter=True, header=False, index=False)
563+
564+
with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb:
565+
ws = wb.active
566+
assert ws.auto_filter.ref is not None
567+
# Without header, filter should start at first row: A1:B2
568+
assert ws.auto_filter.ref == "A1:B2"

0 commit comments

Comments
 (0)