MCPcopy Index your code
hub / github.com/python/cpython / Table

Class Table

Tools/scripts/summarize_stats.py:629–709  ·  view source on GitHub ↗

A Table defines how to convert a set of Stats into a specific set of rows displaying some aspect of the data.

Source from the content-addressed store, hash-verified

627
628
629class Table:
630 """
631 A Table defines how to convert a set of Stats into a specific set of rows
632 displaying some aspect of the data.
633 """
634
635 def __init__(
636 self,
637 column_names: Columns,
638 calc_rows: RowCalculator,
639 join_mode: JoinMode = JoinMode.SIMPLE,
640 ):
641 self.columns = column_names
642 self.calc_rows = calc_rows
643 self.join_mode = join_mode
644
645 def join_row(self, key: str, row_a: tuple, row_b: tuple) -> tuple:
646 match self.join_mode:
647 case JoinMode.SIMPLE:
648 return (key, *row_a, *row_b)
649 case JoinMode.CHANGE | JoinMode.CHANGE_NO_SORT:
650 return (key, *row_a, *row_b, DiffRatio(row_a[0], row_b[0]))
651 case JoinMode.CHANGE_ONE_COLUMN:
652 return (key, row_a[0], row_b[0], DiffRatio(row_a[0], row_b[0]))
653
654 def join_columns(self, columns: Columns) -> Columns:
655 match self.join_mode:
656 case JoinMode.SIMPLE:
657 return (
658 columns[0],
659 *("Base " + x for x in columns[1:]),
660 *("Head " + x for x in columns[1:]),
661 )
662 case JoinMode.CHANGE | JoinMode.CHANGE_NO_SORT:
663 return (
664 columns[0],
665 *("Base " + x for x in columns[1:]),
666 *("Head " + x for x in columns[1:]),
667 ) + ("Change:",)
668 case JoinMode.CHANGE_ONE_COLUMN:
669 return (
670 columns[0],
671 "Base " + columns[1],
672 "Head " + columns[1],
673 "Change:",
674 )
675
676 def join_tables(self, rows_a: Rows, rows_b: Rows) -> tuple[Columns, Rows]:
677 ncols = len(self.columns)
678
679 default = ("",) * (ncols - 1)
680 data_a = {x[0]: x[1:] for x in rows_a}
681 data_b = {x[0]: x[1:] for x in rows_b}
682
683 if len(data_a) != len(rows_a) or len(data_b) != len(rows_b):
684 raise ValueError("Duplicate keys")
685
686 # To preserve ordering, use A's keys as is and then add any in B that

Callers 11

execution_count_sectionFunction · 0.70
pair_count_sectionFunction · 0.70
call_stats_sectionFunction · 0.70
object_stats_sectionFunction · 0.70
gc_stats_sectionFunction · 0.70
iter_optimization_tablesFunction · 0.70
rare_event_sectionFunction · 0.70
meta_stats_sectionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…