pola-rs/polars · error · NotImplementedError

`from_repr` does not support data type {dtype.base_type().__

Error message

`from_repr` does not support data type {dtype.base_type().__name__!r}

What it means

Raised by polars.from_repr when the parsed schema contains a nested (List, Struct, Array) or Object dtype. from_repr reconstructs values from the flat text of the table cells, and nested values are printed in a form (e.g. [1, 2] or {a: 1}) that cannot be unambiguously parsed back, so it refuses with NotImplementedError for those dtypes.

Source

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

            if coldata:
                coldata.pop(idx)

    # init cols as String Series, handle "null" -> None, create schema from repr dtype
    data = [
        pl.Series([(None if v in ("null", "NULL") else v) for v in cd], dtype=String)
        for cd in coldata
    ]
    schema = dict(zip(headers, (_dtype_from_name(d) for d in dtypes), strict=True))
    if schema and data and (n_extend_cols := (len(schema) - len(data))) > 0:
        empty_data = [None] * len(data[0])
        data.extend((pl.Series(empty_data, dtype=String)) for _ in range(n_extend_cols))

    for dtype in set(schema.values()):
        if dtype is not None and (dtype.is_nested() or dtype.is_object()):
            msg = (
                f"`from_repr` does not support data type {dtype.base_type().__name__!r}"
            )
            raise NotImplementedError(msg)

    # Deal with line wrapping by detecting columns which may not be empty, but are
    # anyway, indicating a wrap has occurred.
    str_schema = [(k, String) for k in schema]
    tmp_df = pl.DataFrame(data=data, orient="col", schema=str_schema)
    out_rows: list[Series] = []
    for row_list in tmp_df.iter_rows():
        row = pl.Series(row_list, dtype=String)
        if out_rows and any(
            col == "" and dtype is not None and dtype != String and dtype != Categorical
            for col, dtype in zip(row, schema.values(), strict=True)
        ):
            pad = pl.Series(
                [
                    "" if x == "" or y == "" else " "
                    for x, y in zip(out_rows[-1], row, strict=True)
                ],
                dtype=String,

View on GitHub (pinned to df599052da)

Solutions

  1. Serialize properly instead of via repr: df.write_ipc / write_parquet / write_json and read back with pl.read_*
  2. If nested columns are not needed, exclude them before printing: df.select(pl.col(c) for c in df.columns if not pl.selectors.nested().is_in(df.schema[c]))
  3. Keep from_repr usage limited to flat primitive dtypes (Int, Float, String, Boolean, Date/Datetime without nested wrappers)

Example fix

# before
df = pl.DataFrame({'x': [[1, 2], [3]]})
s = repr(df)
df2 = pl.from_repr(s)  # NotImplementedError: List

# after
df.write_ipc('df.ipc')
df2 = pl.read_ipc('df.ipc')
Defensive patterns

Strategy: fallback

Validate before calling

import polars.selectors as cs

def is_from_repr_safe(df) -> bool:
    return not any(df.select(cs.nested() | cs.Object()).columns)

Try / catch

try:
    obj = pl.from_repr(text)
except NotImplementedError:
    # nested dtypes present: fall back to proper serialization on the producer side
    df.write_ipc('snapshot.ipc')
    obj = pl.read_ipc('snapshot.ipc')

Prevention

When it happens

Trigger: pl.from_repr(repr(df)) where df has any List/Struct/FixedSizeList/Array/Object column; a repr string whose dtype row lists List(Int64), Struct{...}, Array(...), or Object; from_repr round-trip tests over DataFrames produced by group_by/agg (which typically create List columns).

Common situations: Snapshot-testing utilities that store DataFrame reprs and rebuild them via from_repr; doctest fixtures containing aggregated output; attempting to recover data pasted from a notebook that included nested columns.

Related errors


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