pola-rs/polars · error · ValueError

unsupported table format: {table_repr!r}

Error message

unsupported table format: {table_repr!r}

What it means

Raised by polars' internal _build_table_patterns when asked for the parsing regexes of a TableRepr value that is neither TableRepr.UTF8 nor TableRepr.ASCII. TableRepr.patterns looks up cached patterns and builds them on miss, so any new or synthetic enum member without a matching branch lands here. In practice this is defensive internal validation backing from_repr table parsing, not a user-input error.

Source

Thrown at py-polars/src/polars/convert/general.py:764

def _build_table_patterns(table_repr: TableRepr) -> _TablePatterns:
    if table_repr is TableRepr.UTF8:
        return _TablePatterns(
            cell_edge=re.compile(r"^[\W+]*│"),
            cell_split=re.compile(r"[│┆]"),
            header_div=re.compile(r"^[╞═╪╡\s]+$"),
            row_div=re.compile(r"^[├╌┼┤─]+$"),
            rstrip_chars="│ ",
        )
    elif table_repr is TableRepr.ASCII:
        return _TablePatterns(
            cell_edge=re.compile(r"^[\W+]*[|]"),
            cell_split=re.compile(r"[|]"),
            header_div=re.compile(r"^[+=\-\s]+$"),
            row_div=re.compile(r"^[|+\-]+$"),
            rstrip_chars="| ",
        )
    msg = f"unsupported table format: {table_repr!r}"
    raise ValueError(msg)


class TableRepr(Enum):  # noqa: D101
    UTF8 = auto()
    ASCII = auto()

    @property
    def patterns(self) -> _TablePatterns:  # noqa: D102
        try:
            return _TABLE_PATTERNS_CACHE[self]
        except KeyError:
            rx = _build_table_patterns(self)
            _TABLE_PATTERNS_CACHE[self] = rx
            return rx


def _extract_table(data: str) -> tuple[str, TableRepr] | None:
    """Extract a DataFrame table string and infer its format from the input."""

View on GitHub (pinned to df599052da)

Solutions

  1. Use only TableRepr.UTF8 or TableRepr.ASCII; do not fabricate enum members
  2. If extending polars with a new repr format, add a matching branch in _build_table_patterns and a cache entry
  3. If you called a private helper directly, go through the public API (pl.from_repr) instead
Defensive patterns

Strategy: validation

Validate before calling

from polars.convert.general import TableRepr

assert isinstance(table_repr, TableRepr) and table_repr in (TableRepr.UTF8, TableRepr.ASCII), table_repr

Type guard

from polars.convert.general import TableRepr

def is_supported_repr(r: object) -> bool:
    return isinstance(r, TableRepr) and r in (TableRepr.UTF8, TableRepr.ASCII)

Prevention

When it happens

Trigger: Monkeypatching or subclassing TableRepr and adding a new member (e.g. HTML) then calling .patterns on it; passing a raw integer/invalid value to internal table-parsing functions that expect a TableRepr enum; contributing a new repr format to polars without adding a branch in _build_table_patterns.

Common situations: Almost exclusively a polars-internal or contributor error; end users only see it if they tamper with the TableRepr enum or call the private _build_table_patterns / _TablePatterns machinery directly.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/3cc5f3da78bc1689. Report an issue: GitHub.