pola-rs/polars · error
unsupported table format
Error message
unsupported table format: {table_repr!r} What it means
`_build_table_patterns` maps a `TableRepr` variant (UTF8 or ASCII) to the regex patterns used to parse `polars` repr strings. This ValueError is raised when an unknown table representation format is requested.
Solutions
- Pass only valid formats: `TableRepr.UTF8` or `TableRepr.ASCII` (the plain boxed-style and ASCII `+---+`-style reprs Polars actually prints).
- If parsing a custom table, normalize it first (e.g. to UTF8 bordered format).
- Report a bug if this arises from standard `from_repr` usage with a genuine Polars repr.
Example fix
// before pl.from_repr(tbl, table_repr='utf-8') // after pl.from_repr(tbl, table_repr=pl.convert.TableRepr.UTF8)
Defensive patterns
Strategy: validation
Validate before calling
from polars.convert import TableRepr assert table_repr in (TableRepr.UTF8, TableRepr.ASCII)
Try / catch
try:
df = pl.from_repr(s)
except ValueError as e:
if 'unsupported table format' in str(e):
df = pl.from_repr(s) # retry with default format after normalizing input Prevention
- Only pass TableRepr enum members, not raw strings
- Normalize external table text to a supported Polars repr first
When it happens
Trigger: Calling `from_repr` (which reaches `patterns`) with a table representation that is not a recognized `TableRepr` member — effectively an internal/enum-level mismatch rather than a typical user-path error.
Common situations: Programmatically constructing TableRepr from an unvalidated string; custom tooling subclassing or wrapping from_repr with its own format values.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- input string does not contain DataFrame or Series
- arr.dot query vector must be one-dimensional
- can not match overlapping patterns when leftmost == True
- cannot specify both `n` and `fraction`
- `columns` arg should only have unique values, got
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/3cc5f3da78bc1689.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/convert/general.py:770
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 fe841f959e)