ColumnDef

class ColumnDef(name: str, field: Field)[source]

Named tuple defining a single column in a tabular layout.

Each ColumnDef must use its own Field instance; Line.read() mutates field values in place, so sharing Field instances across columns produces incorrect results.

field: Field

Alias for field number 1

name: str

Alias for field number 0

TabularParser

class TabularParser(columns: list[ColumnDef], storage: str | StorageType = '', delimiter: str | bytes | None = None)[source]

Transforms lists of text lines into a dict-of-lists keyed by column name, and provides the inverse format_rows() operation.

Supports both fixed-width positional parsing (delimiter=None, the default) and delimiter-separated parsing. For delimited lines each token is stripped of whitespace before being passed to the field reader; field.starting_position is ignored and only field.size (maximum token width) applies.

Note: splitting uses str.split(delimiter) and does not support quoted fields.

format_rows(data: dict[str, list[Any]]) list[str][source]

Format a dict-of-lists into text lines — the inverse of parse_lines().

Returns one line per row; each line ends with \n because Line.write() always appends one.

parse_lines(lines: list[str]) dict[str, list[Any]][source]

Parse raw text lines into a dict-of-lists keyed by column name.

Lines that raise an exception during reading are filled with None for every column so that row counts always match input length.

static to_dataframe(data: dict[str, list[Any]]) pd.DataFrame[source]

Convert a dict-of-lists to a pandas DataFrame.

Raises ImportError if pandas is not installed.