(
self, fmt_values: Mapping[int, list[str]], indent: int
)
| 479 | ) |
| 480 | |
| 481 | def _write_hierarchical_rows( |
| 482 | self, fmt_values: Mapping[int, list[str]], indent: int |
| 483 | ) -> None: |
| 484 | template = 'rowspan="{span}" valign="top"' |
| 485 | |
| 486 | is_truncated_horizontally = self.fmt.is_truncated_horizontally |
| 487 | is_truncated_vertically = self.fmt.is_truncated_vertically |
| 488 | frame = self.fmt.tr_frame |
| 489 | nrows = len(frame) |
| 490 | |
| 491 | assert isinstance(frame.index, MultiIndex) |
| 492 | idx_values = frame.index._format_multi(sparsify=False, include_names=False) |
| 493 | idx_values = list(zip(*idx_values, strict=True)) |
| 494 | |
| 495 | if self.fmt.sparsify: |
| 496 | # GH3547 |
| 497 | sentinel = lib.no_default |
| 498 | levels = frame.index._format_multi(sparsify=sentinel, include_names=False) |
| 499 | |
| 500 | level_lengths = get_level_lengths(levels, sentinel) |
| 501 | inner_lvl = len(level_lengths) - 1 |
| 502 | if is_truncated_vertically: |
| 503 | # Insert ... row and adjust idx_values and |
| 504 | # level_lengths to take this into account. |
| 505 | ins_row = self.fmt.tr_row_num |
| 506 | inserted = False |
| 507 | for lnum, records in enumerate(level_lengths): |
| 508 | rec_new = {} |
| 509 | for tag, span in list(records.items()): |
| 510 | if tag >= ins_row: |
| 511 | rec_new[tag + 1] = span |
| 512 | elif tag + span > ins_row: |
| 513 | rec_new[tag] = span + 1 |
| 514 | |
| 515 | # GH 14882 - Make sure insertion done once |
| 516 | if not inserted: |
| 517 | dot_row = list(idx_values[ins_row - 1]) |
| 518 | dot_row[-1] = "..." |
| 519 | idx_values.insert(ins_row, tuple(dot_row)) |
| 520 | inserted = True |
| 521 | else: |
| 522 | dot_row = list(idx_values[ins_row]) |
| 523 | dot_row[inner_lvl - lnum] = "..." |
| 524 | idx_values[ins_row] = tuple(dot_row) |
| 525 | else: |
| 526 | rec_new[tag] = span |
| 527 | # If ins_row lies between tags, all cols idx cols |
| 528 | # receive ... |
| 529 | if tag + span == ins_row: |
| 530 | rec_new[ins_row] = 1 |
| 531 | if lnum == 0: |
| 532 | idx_values.insert( |
| 533 | ins_row, tuple(["..."] * len(level_lengths)) |
| 534 | ) |
| 535 | |
| 536 | # GH 14882 - Place ... in correct level |
| 537 | elif inserted: |
| 538 | dot_row = list(idx_values[ins_row]) |
no test coverage detected