mlrl.testbed.experiments.table module¶
Author Michael Rapp (michael.rapp.ml@gmail.com)
Provides classes for representing tables.
- class mlrl.testbed.experiments.table.Alignment(*values)¶
Bases:
EnumAll possible alignments of a table column.
- AUTO = None¶
- CENTER = 'center'¶
- LEFT = 'left'¶
- RIGHT = 'right'¶
- class mlrl.testbed.experiments.table.Column¶
Bases:
Iterable[Any|None],ABCProvides access to a single column of a table.
- class mlrl.testbed.experiments.table.ColumnWiseTable¶
Bases:
TableA table to which new columns can be added one by one.
- class Column(table: ColumnWiseTable, column_index: int)¶
Bases:
ColumnProvides access to a single column of a ColumnWiseTable.
- class HeaderRow(table: ColumnWiseTable)¶
Bases:
HeaderRowProvides access to the headers of a ColumnWiseTable.
- class Row(table: ColumnWiseTable, row_index: int)¶
Bases:
RowProvides access to a single row of a ColumnWiseTable.
- add_column(*values: Any | None, header: Any | None = None, alignment: Alignment | None = None, position: int = -1) ColumnWiseTable¶
Adds a new column to a table at a specific position.
- Parameters:
values – The values in the column
header – The header of the column or None
alignment – The alignment of the column or None
position – The position, the column should be added at, or -1, if the column should be added at the end
- Returns:
The modified table
- property alignments: list[Alignment | None] | None¶
The individual alignments of the columns in the table or None, if no alignments have been specified.
- property columns: Generator[Column, None, None]¶
A generator that provides access to the individual columns in the table.
- property header_row: HeaderRow | None¶
The header row of the table or None, if the table does not have any headers.
- property rows: Generator[Row, None, None]¶
A generator that provides access to the individual rows in the table.
- slice(*column_indices: int) ColumnWiseTable¶
Creates and returns a copy of this table that contains the columns with specific indices in the given order.
- Parameters:
column_indices – The indices of the columns to be sliced
- Returns:
The table that has been created
- sort_by_headers() ColumnWiseTable¶
Sorts the columns in the table by their headers.
- Returns:
The sorted table
- to_column_wise_table() ColumnWiseTable¶
Creates and returns a ColumnWiseTable from this table.
- Returns:
The ColumnWiseTable that has been created
- to_row_wise_table() RowWiseTable¶
Creates and returns a RowWiseTable from this table.
- Returns:
The RowWiseTable that has been created
- class mlrl.testbed.experiments.table.HeaderRow¶
Bases:
Iterable[Any|None],ABCProvides access to the headers of a table.
- class mlrl.testbed.experiments.table.Row¶
Bases:
Iterable[Any|None],ABCProvides access to a single row of a table.
- class mlrl.testbed.experiments.table.RowWiseTable(*headers: Any | None, alignments: list[Alignment | None] | None = None)¶
Bases:
TableA table to which new rows can be added one by one.
- class Column(table: RowWiseTable, column_index: int)¶
Bases:
ColumnProvides access to a single column of a RowWiseTable.
- class HeaderRow(table: RowWiseTable)¶
Bases:
HeaderRowProvides access to the headers of a RowWiseTable.
- class Row(table: RowWiseTable, row_index: int)¶
Bases:
RowProvides access to a single row of a RowWiseTable.
- add_row(*values: Any | None, position: int = -1)¶
Adds a new row at a specific position of the table.
- Parameters:
values – The values in the row
position – The position where the row should be added or -1, if the row should be added at the end
- Returns:
The modified table
- static aggregate(*tables: Table) RowWiseTable¶
Creates and returns a RowWiseTable that contains all rows of the given tables. The given tables must all have the same headers.
- Parameters:
tables – The tables to aggregate
- Returns:
A RowWiseTable that contains all rows of the given tables
- property alignments: list[Alignment | None] | None¶
The individual alignments of the columns in the table or None, if no alignments have been specified.
- property columns: Generator[Column, None, None]¶
A generator that provides access to the individual columns in the table.
- copy() RowWiseTable¶
Creates and returns a copy of this table.
- Returns:
The copy that has been created
- property header_row: HeaderRow | None¶
The header row of the table or None, if the table does not have any headers.
- property rows: Generator[Row, None, None]¶
A generator that provides access to the individual rows in the table.
- sort_by_columns(column_index: int, *additional_column_indices: int, descending: bool = False) RowWiseTable¶
Sorts the rows in the table by the values in one or several columns.
- Parameters:
column_index – The index of the column to sort by
additional_column_indices – Additional indices of columns to sort by
descending – True, if the rows should be sorted in descending order, False, if they should be sorted in ascending order
- Returns:
The sorted table
- to_column_wise_table() ColumnWiseTable¶
Creates and returns a ColumnWiseTable from this table.
- Returns:
The ColumnWiseTable that has been created
- to_row_wise_table() RowWiseTable¶
Creates and returns a RowWiseTable from this table.
- Returns:
The RowWiseTable that has been created
- class mlrl.testbed.experiments.table.Table¶
Bases:
ABCAn abstract base class for all tables.
- class Format(*values)¶
Bases:
StrEnumAll formats that can be used for formatting tables.
- OUTLINE = 'simple_outline'¶
- PLAIN = 'plain'¶
- SIMPLE = 'simple'¶
- abstract property alignments: list[Alignment | None] | None¶
The individual alignments of the columns in the table or None, if no alignments have been specified.
- abstract property columns: Generator[Column, None, None]¶
A generator that provides access to the individual columns in the table.
- format(auto_rotate: bool = True, table_format: Format | None = None, separator_indices: list[int] | None = None) str¶
Creates and returns a textual representation of the table.
- Parameters:
auto_rotate – True, if tables with a single row should automatically be rotated for legibility, False otherwise
table_format – The format that should be used for formatting the table or None, if the default should be used
separator_indices – A list that contains the indices of the row at which a separator should be inserted, or None if no separators should be inserted
- Returns:
The textual representation that has been created
- abstract property header_row: HeaderRow | None¶
The header row of the table or None, if the table does not have any headers.
- abstract property rows: Generator[Row, None, None]¶
A generator that provides access to the individual rows in the table.
- abstractmethod to_column_wise_table() ColumnWiseTable¶
Creates and returns a ColumnWiseTable from this table.
- Returns:
The ColumnWiseTable that has been created
- abstractmethod to_row_wise_table() RowWiseTable¶
Creates and returns a RowWiseTable from this table.
- Returns:
The RowWiseTable that has been created