|
9 | 9 |
|
10 | 10 | from pandas import (
|
11 | 11 | DataFrame,
|
| 12 | + MultiIndex, |
| 13 | + Period, |
| 14 | + period_range, |
12 | 15 | read_excel,
|
13 | 16 | )
|
14 | 17 | import pandas._testing as tm
|
@@ -333,3 +336,39 @@ def test_styler_to_s3(s3_public_bucket, s3so):
|
333 | 336 | f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so
|
334 | 337 | )
|
335 | 338 | 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