Skip to content

Commit be86dd0

Browse files
committed
Modify the tests
1 parent ea8e626 commit be86dd0

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
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"

pandas/tests/io/formats/test_to_excel.py

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

1010
from pandas.errors import CSSWarning
1111

12-
from pandas import (
13-
DataFrame,
14-
MultiIndex,
15-
Timestamp,
16-
period_range,
17-
to_datetime,
18-
)
1912
import pandas._testing as tm
2013

2114
from pandas.io.formats.excel import (
@@ -435,35 +428,3 @@ def test_css_excel_cell_cache(styles, cache_hits, cache_misses):
435428

436429
assert cache_info.hits == cache_hits
437430
assert cache_info.misses == cache_misses
438-
439-
440-
def test_format_hierarchical_rows_with_periodindex():
441-
# GH#60099
442-
period_index = period_range(start="2006-10-06", end="2006-10-07", freq="D")
443-
df = DataFrame({"A": [0, 0]}, index=period_index)
444-
converter = CSSToExcelConverter()
445-
cells: list[CssExcelCell] = list(converter._format_hierarchical_rows(df))
446-
for cell in cells:
447-
assert isinstance(cell.val, Timestamp), "Expected cell value to be a Timestamp"
448-
assert cell.val in to_datetime(
449-
["2006-10-06", "2006-10-07"]
450-
), "Unexpected cell value"
451-
452-
453-
def test_format_hierarchical_rows_with_period():
454-
# GH#60099
455-
period_index = period_range(start="2006-10-06", end="2006-10-07", freq="D")
456-
number_index = ["1", "2"]
457-
df = DataFrame(
458-
{"A": [0, 0]}, index=MultiIndex.from_arrays([period_index, number_index])
459-
)
460-
converter = CSSToExcelConverter()
461-
cells: list[CssExcelCell] = list(converter._format_hierarchical_rows(df))
462-
for cell in cells:
463-
if cell.css_col == 0:
464-
assert isinstance(
465-
cell.val, Timestamp
466-
), "Expected cell value to be a Timestamp"
467-
assert cell.val in to_datetime(
468-
["2006-10-06", "2006-10-07"]
469-
), "Unexpected cell value"

0 commit comments

Comments
 (0)