{"record":{"id":"5742f47d46fb964b","repo":"pola-rs/polars","slug":"input-string-does-not-contain-dataframe-or-series","errorCode":null,"errorMessage":"input string does not contain DataFrame or Series","messagePattern":"input string does not contain DataFrame or Series","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/convert/general.py","lineNumber":906,"sourceCode":"    ... )\n    >>> s.to_list()\n    [True, False, True]\n    \"\"\"\n    # find DataFrame table...\n    if (tbl_repr_type := _extract_table(data)) is not None:\n        return _from_dataframe_repr(*tbl_repr_type)\n\n    # ...or Series in the given string\n    m = re.search(\n        pattern=r\"(?:shape: (\\(\\d+,\\))\\n.*?)?Series:\\s+([^\\n]+)\\s+\\[([^\\n]+)](.*)\",\n        string=data,\n        flags=re.DOTALL,\n    )\n    if m is not None:\n        return _from_series_repr(m)\n\n    msg = \"input string does not contain DataFrame or Series\"\n    raise ValueError(msg)\n\n\ndef _from_dataframe_repr(tbl: str, table_repr: TableRepr) -> DataFrame:\n    \"\"\"Reconstruct a DataFrame from a table repr string.\"\"\"\n    from polars.datatypes.convert import dtype_short_repr_to_dtype\n    from polars.io.database._inference import dtype_from_database_typename\n\n    def _dtype_from_name(tp: str | None) -> PolarsDataType | None:\n        return (\n            None\n            if tp is None\n            else (\n                dtype_short_repr_to_dtype(tp)\n                or dtype_from_database_typename(tp, raise_unmatched=False)\n            )\n        )\n\n    # associated regex patterns for the given table format","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/convert/general.py#L888-L924","documentation":"from_repr parses a polars DataFrame/Series textual repr; when neither the DataFrame pattern nor the Series regex matches the input string it raises ValueError — the string is not a polars repr that can be reconstructed.","triggerScenarios":"Calling `pl.from_repr(s)` where `s` is truncated, has altered borders/column widths, is a different table style, or is not a Polars repr at all (e.g. markdown, pandas repr).","commonSituations":"Copy-pasting from logs where long lines were wrapped or ellipsized; repr printed with `PL_FMT_STR_LEN` or console options that changed formatting; copying a pandas to_string() output by mistake.","solutions":["Copy the repr verbatim from a Polars `print(df)` output, including the `shape: ...` header line and full borders.","Ensure nothing was truncated: use sufficient terminal width or `pl.Config.set_tbl_width_chars`/`set_tbl_rows` to print without ellipsis.","If the string is not a Polars repr, parse it another way (e.g. write/read CSV instead)."],"exampleFix":"// before\npl.from_repr('a | b\\n1 | 2')\n// after\npl.from_repr('shape: (1, 2)\\n┌─────┬─────┐\\n│ a   ┆ b   │\\n│ --- ┆ --- │\\n│ i64 ┆ i64 │\\n╞═════╪═════╡\\n│ 1   ┆ 2   │\\n└─────┴─────┘')","handlingStrategy":"validation","validationCode":"if not (s.startswith('shape:') or '┌' in s or '+---' in s):\n    raise ValueError('input is not a polars DataFrame/Series repr')","typeGuard":"def looks_like_polars_repr(s: str) -> bool:\n    return ('shape:' in s) or ('┌' in s and '└' in s) or ('+---' in s)","tryCatchPattern":"try:\n    df = pl.from_repr(s)\nexcept ValueError:\n    df = pl.read_json(io.StringIO(s))  # alternate parse path","preventionTips":["Copy reprs verbatim including the shape header","Widen terminal/disable truncation before printing (pl.Config)","Do not mix pandas to_string output with from_repr"],"tags":["python","polars","value-error","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}