{"record":{"id":"1aaa2dee1a9ce3e5","repo":"pola-rs/polars","slug":"dataframe-should-contain-only-string-repr-data-fo","errorCode":null,"errorMessage":"DataFrame should contain only String repr data; found {tp!r}","messagePattern":"DataFrame should contain only String repr data; found (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/various.py","lineNumber":340,"sourceCode":"\n    Parameters\n    ----------\n    df\n        Dataframe containing string-repr column data.\n    schema\n        DataFrame schema containing the desired end-state types.\n\n    Notes\n    -----\n    Table repr strings are less strict (or different) than equivalent CSV data, so need\n    special handling; as this function is only used for reprs, parsing is flexible.\n    \"\"\"\n    tp: PolarsDataType | None\n    if not df.is_empty():\n        for tp in df.schema.values():\n            if tp != String:\n                msg = f\"DataFrame should contain only String repr data; found {tp!r}\"\n                raise TypeError(msg)\n\n    special_floats = {\"-inf\", \"+inf\", \"inf\", \"nan\"}\n\n    # duration string scaling\n    ns_sec = 1_000_000_000\n    duration_scaling = {\n        \"ns\": 1,\n        \"us\": 1_000,\n        \"µs\": 1_000,\n        \"ms\": 1_000_000,\n        \"s\": ns_sec,\n        \"m\": ns_sec * 60,\n        \"h\": ns_sec * 60 * 60,\n        \"d\": ns_sec * 3_600 * 24,\n        \"w\": ns_sec * 3_600 * 24 * 7,\n    }\n\n    # identify duration units and convert to nanoseconds","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/various.py#L322-L358","documentation":"TypeError from _cast_repr_strings_with_schema (py-polars/src/polars/_utils/various.py:326-341). This is an internal helper used by polars' repr round-trip machinery (pl.from_repr / pl.from_reprs in polars/convert/general.py): the table scraped from a text/clipboard repr is expected to contain only String columns, which are then cast to the schema inferred from the header. If any column of the parsed repr frame is not String, the invariant is broken and this error names the offending dtype.","triggerScenarios":"Calling pl.from_repr(...) or pl.from_reprs(...) with a hand-edited or already-typed table (e.g. pasted from a session where values were not the default string repr), or where the internal parser produced a non-string column. Not part of the stable public API surface for normal frame construction.","commonSituations":"Doctests and tutorials that use from_repr; copying a DataFrame repr that was produced with a custom formatting hook; internal code changes in how reprs parse.","solutions":["Re-copy the repr straight from a real polars DataFrame/Series output so all cells are plain strings","Prefer constructing frames from explicit data (pl.DataFrame({...})) instead of repr parsing in production code","If wrapping from_repr, ensure the input block preserves the default string table shape (headers + quoted/plain string cells)"],"exampleFix":"# before\n# repr block with a column already in {i64} form pasted into from_repr -> TypeError\n\n# after\ndf = pl.from_repr(\n'''\n┌─────┬──────┐\n│ a   ┆ b    │\n│ --- ┆ ---  │\n│ i64 ┆ str  │\n├─────┼──────┤\n│ 1   ┆ x    │\n└─────┴──────┘\n''')","handlingStrategy":"validation","validationCode":"def repr_block_ok(lines: list[str]) -> bool:\n    # all data rows must be parseable as plain strings under the header\n    return len(lines) >= 3 and all(line.strip() for line in lines)","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.from_repr(text)\nexcept TypeError:\n    df = None  # fall back to explicit construction from parsed values","preventionTips":["Use from_repr only for reprs copied verbatim from polars output (docs/tests)","Build production frames from real data, never from scraped repr text","Keep custom formatting hooks out of sessions whose reprs feed from_repr"],"tags":["polars","from-repr","internal","typeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}