{"record":{"id":"d94d38639e6c1811","repo":"pola-rs/polars","slug":"from-repr-does-not-support-data-type-dtype-base","errorCode":null,"errorMessage":"`from_repr` does not support data type {dtype.base_type().__name__!r}","messagePattern":"`from_repr` does not support data type (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/convert/general.py","lineNumber":1004,"sourceCode":"            if coldata:\n                coldata.pop(idx)\n\n    # init cols as String Series, handle \"null\" -> None, create schema from repr dtype\n    data = [\n        pl.Series([(None if v in (\"null\", \"NULL\") else v) for v in cd], dtype=String)\n        for cd in coldata\n    ]\n    schema = dict(zip(headers, (_dtype_from_name(d) for d in dtypes), strict=True))\n    if schema and data and (n_extend_cols := (len(schema) - len(data))) > 0:\n        empty_data = [None] * len(data[0])\n        data.extend((pl.Series(empty_data, dtype=String)) for _ in range(n_extend_cols))\n\n    for dtype in set(schema.values()):\n        if dtype is not None and (dtype.is_nested() or dtype.is_object()):\n            msg = (\n                f\"`from_repr` does not support data type {dtype.base_type().__name__!r}\"\n            )\n            raise NotImplementedError(msg)\n\n    # Deal with line wrapping by detecting columns which may not be empty, but are\n    # anyway, indicating a wrap has occurred.\n    str_schema = [(k, String) for k in schema]\n    tmp_df = pl.DataFrame(data=data, orient=\"col\", schema=str_schema)\n    out_rows: list[Series] = []\n    for row_list in tmp_df.iter_rows():\n        row = pl.Series(row_list, dtype=String)\n        if out_rows and any(\n            col == \"\" and dtype is not None and dtype != String and dtype != Categorical\n            for col, dtype in zip(row, schema.values(), strict=True)\n        ):\n            pad = pl.Series(\n                [\n                    \"\" if x == \"\" or y == \"\" else \" \"\n                    for x, y in zip(out_rows[-1], row, strict=True)\n                ],\n                dtype=String,","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/convert/general.py#L986-L1022","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Serialize properly instead of via repr: df.write_ipc / write_parquet / write_json and read back with pl.read_*","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]))","Keep from_repr usage limited to flat primitive dtypes (Int, Float, String, Boolean, Date/Datetime without nested wrappers)"],"exampleFix":"# before\ndf = pl.DataFrame({'x': [[1, 2], [3]]})\ns = repr(df)\ndf2 = pl.from_repr(s)  # NotImplementedError: List\n\n# after\ndf.write_ipc('df.ipc')\ndf2 = pl.read_ipc('df.ipc')","handlingStrategy":"fallback","validationCode":"import polars.selectors as cs\n\ndef is_from_repr_safe(df) -> bool:\n    return not any(df.select(cs.nested() | cs.Object()).columns)","typeGuard":null,"tryCatchPattern":"try:\n    obj = pl.from_repr(text)\nexcept NotImplementedError:\n    # nested dtypes present: fall back to proper serialization on the producer side\n    df.write_ipc('snapshot.ipc')\n    obj = pl.read_ipc('snapshot.ipc')","preventionTips":["Snapshot DataFrames with write_ipc/write_parquet, not repr, whenever nested dtypes can appear","Watch for List columns created by group_by(...).agg(...) before generating repr fixtures","Run a dtype audit (df.schema) before choosing repr-based round-trips in tests"],"tags":["from-repr","nested-dtypes","not-implemented","serialization"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}