neuralib.util.table.Table

class neuralib.util.table.Table[source]

Bases: JupyterMixin

A console renderable to draw a table.

Args:

headers (Union[Column, str]): Column headers, either as a string, or :class:`~rich.table.Column` instance. title (Union[str, Text], optional): The title of the table rendered at the top. Defaults to None. caption (Union[str, Text], optional): The table caption rendered below. Defaults to None. width (int, optional): The width in characters of the table, or ``None`` to automatically fit. Defaults to None. min_width (Optional[int], optional): The minimum width of the table, or ``None`` for no minimum. Defaults to None. box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD. safe_box (Optional[bool], optional): Disable box characters that don’t display on windows legacy terminal with *raster fonts. Defaults to True. padding (PaddingDimensions, optional): Padding for cells (top, right, bottom, left). Defaults to (0, 1). collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to False. pad_edge (bool, optional): Enable padding of edge cells. Defaults to True. expand (bool, optional): Expand the table to fit the available space if True, otherwise the table width will be auto-calculated. Defaults to False. show_header (bool, optional): Show a header row. Defaults to True. show_footer (bool, optional): Show a footer row. Defaults to False. show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True. show_lines (bool, optional): Draw lines between every row. Defaults to False. leading (int, optional): Number of blank lines between rows (precludes show_lines). Defaults to 0. style (Union[str, Style], optional): Default style for the table. Defaults to “none”. row_styles (List[Union, str], optional): Optional list of row styles, if more than one style is given then the styles will alternate. Defaults to None. header_style (Union[str, Style], optional): Style of the header. Defaults to “table.header”. footer_style (Union[str, Style], optional): Style of the footer. Defaults to “table.footer”. border_style (Union[str, Style], optional): Style of the border. Defaults to None. title_style (Union[str, Style], optional): Style of the title. Defaults to None. caption_style (Union[str, Style], optional): Style of the caption. Defaults to None. title_justify (str, optional): Justify method for title. Defaults to “center”. caption_justify (str, optional): Justify method for caption. Defaults to “center”. highlight (bool, optional): Highlight cell contents (if str). Defaults to False.

__init__(*headers, title=None, caption=None, width=None, min_width=None, box=Box(...), safe_box=None, padding=(0, 1), collapse_padding=False, pad_edge=True, expand=False, show_header=True, show_footer=False, show_edge=True, show_lines=False, leading=0, style='none', row_styles=None, header_style='table.header', footer_style='table.footer', border_style=None, title_style=None, caption_style=None, title_justify='center', caption_justify='center', highlight=False)[source]
Parameters:
  • headers (Column | str)

  • title (str | Text | None)

  • caption (str | Text | None)

  • width (int | None)

  • min_width (int | None)

  • box (Box | None)

  • safe_box (bool | None)

  • padding (int | Tuple[int] | Tuple[int, int] | Tuple[int, int, int, int])

  • collapse_padding (bool)

  • pad_edge (bool)

  • expand (bool)

  • show_header (bool)

  • show_footer (bool)

  • show_edge (bool)

  • show_lines (bool)

  • leading (int)

  • style (str | Style)

  • row_styles (Iterable[str | Style] | None)

  • header_style (str | Style | None)

  • footer_style (str | Style | None)

  • border_style (str | Style | None)

  • title_style (str | Style | None)

  • caption_style (str | Style | None)

  • title_justify (JustifyMethod)

  • caption_justify (JustifyMethod)

  • highlight (bool)

Return type:

None

Methods

__init__(*headers[, title, caption, width, ...])

add_column([header, footer, header_style, ...])

Add a column to the table.

add_row(*renderables[, style, end_section])

Add a row of renderables.

add_section()

Add a new section (draw a line after current row).

get_row_style(console, index)

Get the current row style.

grid(*headers[, padding, collapse_padding, ...])

Get a table with no lines, headers, or footer.

Attributes

expand

Setting a non-None self.width implies expand.

padding

Get cell padding.

row_count

Get the current number of rows.

columns

rows

__init__(*headers, title=None, caption=None, width=None, min_width=None, box=Box(...), safe_box=None, padding=(0, 1), collapse_padding=False, pad_edge=True, expand=False, show_header=True, show_footer=False, show_edge=True, show_lines=False, leading=0, style='none', row_styles=None, header_style='table.header', footer_style='table.footer', border_style=None, title_style=None, caption_style=None, title_justify='center', caption_justify='center', highlight=False)[source]
Parameters:
  • headers (Column | str)

  • title (str | Text | None)

  • caption (str | Text | None)

  • width (int | None)

  • min_width (int | None)

  • box (Box | None)

  • safe_box (bool | None)

  • padding (int | Tuple[int] | Tuple[int, int] | Tuple[int, int, int, int])

  • collapse_padding (bool)

  • pad_edge (bool)

  • expand (bool)

  • show_header (bool)

  • show_footer (bool)

  • show_edge (bool)

  • show_lines (bool)

  • leading (int)

  • style (str | Style)

  • row_styles (Iterable[str | Style] | None)

  • header_style (str | Style | None)

  • footer_style (str | Style | None)

  • border_style (str | Style | None)

  • title_style (str | Style | None)

  • caption_style (str | Style | None)

  • title_justify (JustifyMethod)

  • caption_justify (JustifyMethod)

  • highlight (bool)

Return type:

None

columns: List[Column]
rows: List[Row]
classmethod grid(*headers, padding=0, collapse_padding=True, pad_edge=False, expand=False)[source]

Get a table with no lines, headers, or footer.

Args:

*headers (Union[Column, str]): Column headers, either as a string, or Column instance. padding (PaddingDimensions, optional): Get padding around cells. Defaults to 0. collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to True. pad_edge (bool, optional): Enable padding around edges of table. Defaults to False. expand (bool, optional): Expand the table to fit the available space if True, otherwise the table width will be auto-calculated. Defaults to False.

Returns:

Table: A table instance.

Parameters:
  • headers (Column | str)

  • padding (int | Tuple[int] | Tuple[int, int] | Tuple[int, int, int, int])

  • collapse_padding (bool)

  • pad_edge (bool)

  • expand (bool)

Return type:

Table

property expand: bool

Setting a non-None self.width implies expand.

property row_count: int

Get the current number of rows.

get_row_style(console, index)[source]

Get the current row style.

Parameters:
  • console (Console)

  • index (int)

Return type:

str | Style

property padding: Tuple[int, int, int, int]

Get cell padding.

add_column(header='', footer='', *, header_style=None, highlight=None, footer_style=None, style=None, justify='left', vertical='top', overflow='ellipsis', width=None, min_width=None, max_width=None, ratio=None, no_wrap=False)[source]

Add a column to the table.

Args:
header (RenderableType, optional): Text or renderable for the header.

Defaults to “”.

footer (RenderableType, optional): Text or renderable for the footer.

Defaults to “”.

header_style (Union[str, Style], optional): Style for the header, or None for default. Defaults to None. highlight (bool, optional): Whether to highlight the text. The default of None uses the value of the table (self) object. footer_style (Union[str, Style], optional): Style for the footer, or None for default. Defaults to None. style (Union[str, Style], optional): Style for the column cells, or None for default. Defaults to None. justify (JustifyMethod, optional): Alignment for cells. Defaults to “left”. vertical (VerticalAlignMethod, optional): Vertical alignment, one of “top”, “middle”, or “bottom”. Defaults to “top”. overflow (OverflowMethod): Overflow method: “crop”, “fold”, “ellipsis”. Defaults to “ellipsis”. width (int, optional): Desired width of column in characters, or None to fit to contents. Defaults to None. min_width (Optional[int], optional): Minimum width of column, or None for no minimum. Defaults to None. max_width (Optional[int], optional): Maximum width of column, or None for no maximum. Defaults to None. ratio (int, optional): Flexible ratio for the column (requires Table.expand or Table.width). Defaults to None. no_wrap (bool, optional): Set to True to disable wrapping of this column.

Parameters:
  • header (RenderableType)

  • footer (RenderableType)

  • header_style (str | Style | None)

  • highlight (bool | None)

  • footer_style (str | Style | None)

  • style (str | Style | None)

  • justify (JustifyMethod)

  • vertical (VerticalAlignMethod)

  • overflow (OverflowMethod)

  • width (int | None)

  • min_width (int | None)

  • max_width (int | None)

  • ratio (int | None)

  • no_wrap (bool)

Return type:

None

add_row(*renderables, style=None, end_section=False)[source]

Add a row of renderables.

Args:
*renderables (None or renderable): Each cell in a row must be a renderable object (including str),

or None for a blank cell.

style (StyleType, optional): An optional style to apply to the entire row. Defaults to None. end_section (bool, optional): End a section and draw a line. Defaults to False.

Raises:

errors.NotRenderableError: If you add something that can’t be rendered.

Parameters:
  • renderables (RenderableType | None)

  • style (str | Style | None)

  • end_section (bool)

Return type:

None

add_section()[source]

Add a new section (draw a line after current row).

Return type:

None