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: Enum

All possible alignments of a table column.

AUTO = None
CENTER = 'center'
LEFT = 'left'
RIGHT = 'right'
class mlrl.testbed.experiments.table.Column

Bases: Iterable[Any | None], ABC

Provides access to a single column of a table.

abstract property header: Any | None

The header of the column.

abstract property num_rows: int

The number of rows in the table.

class mlrl.testbed.experiments.table.ColumnWiseTable

Bases: Table

A table to which new columns can be added one by one.

class Column(table: ColumnWiseTable, column_index: int)

Bases: Column

Provides access to a single column of a ColumnWiseTable.

property header: Any | None

The header of the column.

property num_rows: int

The number of rows in the table.

class HeaderRow(table: ColumnWiseTable)

Bases: HeaderRow

Provides access to the headers of a ColumnWiseTable.

property num_columns: int

The number of columns in the table.

class Row(table: ColumnWiseTable, row_index: int)

Bases: Row

Provides access to a single row of a ColumnWiseTable.

property num_columns: int

The number of columns in the table.

add_column(*values: Any | None, header: Any | None = None, alignment: Alignment | None = None) ColumnWiseTable

Adds a new column to the end of the table.

Parameters:
  • values – The values in the column

  • header – The header of the column or None

  • alignment – The alignment of the column or None

Returns:

The modified table

property alignments: List[Alignment] | 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 num_columns: int

The number of columns in the table.

property num_rows: int

The number of rows in the table.

property rows: Generator[Row, None, None]

A generator that provides access to the individual rows in the table.

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], ABC

Provides access to the headers of a table.

abstract property num_columns: int

The number of columns in the table.

class mlrl.testbed.experiments.table.Row

Bases: Iterable[Any | None], ABC

Provides access to a single row of a table.

abstract property num_columns: int

The number of columns in the table.

class mlrl.testbed.experiments.table.RowWiseTable(*headers: Any | None, alignments: List[Alignment] | None = None)

Bases: Table

A table to which new rows can be added one by one.

class Column(table: RowWiseTable, column_index: int)

Bases: Column

Provides access to a single column of a RowWiseTable.

property header: Any | None

The header of the column.

property num_rows: int

The number of rows in the table.

class HeaderRow(table: RowWiseTable)

Bases: HeaderRow

Provides access to the headers of a RowWiseTable.

property num_columns: int

The number of columns in the table.

class Row(table: RowWiseTable, row_index: int)

Bases: Row

Provides access to a single row of a RowWiseTable.

property num_columns: int

The number of columns in the table.

add_row(*values: Any | None)

Adds a new row to the end of the table.

Parameters:

values – The values in the row

Returns:

The modified table

property alignments: List[Alignment] | 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 num_columns: int

The number of columns in the table.

property num_rows: int

The number of rows in the table.

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: ABC

An abstract base class for all tables.

abstract property alignments: List[Alignment] | 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) 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

Returns:

The textual representation that has been created

property has_headers: bool

True, if the table has any headers, False otherwise.

abstract property header_row: HeaderRow | None

The header row of the table or None, if the table does not have any headers.

property num_cells: int

The number of cells in the table.

abstract property num_columns: int

The number of columns in the table.

abstract property num_rows: int

The number of rows in the table.

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