Skip to content

Commit 1d709d1

Browse files
committed
Modify the tests
1 parent eced532 commit 1d709d1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pandas/tests/io/excel/test_style.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
from pandas import (
1111
DataFrame,
12+
MultiIndex,
13+
Period,
14+
period_range,
1215
read_excel,
1316
)
1417
import pandas._testing as tm
@@ -333,3 +336,39 @@ def test_styler_to_s3(s3_public_bucket, s3so):
333336
f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so
334337
)
335338
tm.assert_frame_equal(result, df)
339+
340+
341+
def test_format_hierarchical_rows_periodindex_merge_cells():
342+
# GH#60099
343+
df = DataFrame(
344+
{"A": [1, 2]},
345+
index=MultiIndex.from_arrays(
346+
[period_range("2023-01", "2023-02", freq="M"), ["X", "Y"]],
347+
names=["date", "category"],
348+
),
349+
)
350+
formatter = ExcelFormatter(df, merge_cells=True)
351+
formatted_cells = list(formatter._format_hierarchical_rows())
352+
353+
for cell in formatted_cells:
354+
assert not isinstance(
355+
cell.val, Period
356+
), "Period should be converted to Timestamp"
357+
358+
359+
def test_format_hierarchical_rows_periodindex_no_merge_cells():
360+
# GH#60099
361+
df = DataFrame(
362+
{"A": [1, 2]},
363+
index=MultiIndex.from_arrays(
364+
[period_range("2023-01", "2023-02", freq="M"), ["X", "Y"]],
365+
names=["date", "category"],
366+
),
367+
)
368+
formatter = ExcelFormatter(df, merge_cells=False)
369+
formatted_cells = list(formatter._format_hierarchical_rows())
370+
371+
for cell in formatted_cells:
372+
assert not isinstance(
373+
cell.val, Period
374+
), "Period should be converted to Timestamp"

0 commit comments

Comments
 (0)