{"record":{"id":"a64f61e3b38e20ad","repo":"pola-rs/polars","slug":"expected-pandas-dataframe-or-series-got-qualifie","errorCode":null,"errorMessage":"expected pandas DataFrame or Series, got {qualified_type_name(data)!r}","messagePattern":"expected pandas DataFrame or Series, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/convert/general.py","lineNumber":735,"sourceCode":"    \"\"\"\n    if include_index and isinstance(data, pd.Series):\n        data = data.reset_index()\n\n    if isinstance(data, (pd.Series, pd.Index, pd.DatetimeIndex)):\n        return wrap_s(pandas_to_pyseries(\"\", data, nan_to_null=nan_to_null))\n    elif isinstance(data, pd.DataFrame):\n        return wrap_df(\n            pandas_to_pydf(\n                data,\n                schema_overrides=schema_overrides,\n                rechunk=rechunk,\n                nan_to_null=nan_to_null,\n                include_index=include_index,\n            )\n        )\n    else:\n        msg = f\"expected pandas DataFrame or Series, got {qualified_type_name(data)!r}\"\n        raise TypeError(msg)\n\n\n@dataclass(frozen=True, slots=True)\nclass _TablePatterns:\n    \"\"\"Format-specific regex patterns for table parsing.\"\"\"\n\n    cell_edge: re.Pattern[str]\n    cell_split: re.Pattern[str]\n    header_div: re.Pattern[str]\n    row_div: re.Pattern[str]\n    rstrip_chars: str\n\n\n_TABLE_PATTERNS_CACHE: dict[TableRepr, _TablePatterns] = {}\n\n\ndef _build_table_patterns(table_repr: TableRepr) -> _TablePatterns:\n    if table_repr is TableRepr.UTF8:","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/convert/general.py#L717-L753","documentation":"from_pandas only accepts a pandas DataFrame, Series, Index or DatetimeIndex; any other object (including numpy arrays or plain sequences) falls through to the else branch and raises TypeError naming the actual received type.","triggerScenarios":"Calling `pl.from_pandas(data)` with a non-pandas object such as a list, dict, pyarrow Table, numpy array, or None.","commonSituations":"Mixing up converters — passing Arrow or native Python containers to from_pandas; refactor of a pipeline changed the input type upstream; passing polars objects back in.","solutions":["Ensure the input is `pd.DataFrame` or `pd.Series`; convert if needed: `pd.DataFrame(obj)`.","Use `pl.from_arrow` for pyarrow objects, `pl.from_dict` for dicts, `pl.from_records` for lists of records.","Check `isinstance(data, (pd.DataFrame, pd.Series))` before calling."],"exampleFix":"// before\npl.from_pandas(pa.table({'a': [1]}))\n// after\npl.from_arrow(pa.table({'a': [1]}))","handlingStrategy":"type-guard","validationCode":"import pandas as pd\nif not isinstance(data, (pd.DataFrame, pd.Series)):\n    raise TypeError(f'from_pandas requires pandas DataFrame/Series, got {type(data)}')","typeGuard":"def is_pandas_frame(x) -> bool:\n    import pandas as pd\n    return isinstance(x, (pd.DataFrame, pd.Series))","tryCatchPattern":"try:\n    df = pl.from_pandas(data)\nexcept TypeError:\n    df = pl.from_arrow(data) if hasattr(data, '__arrow_c_stream__') else pl.DataFrame(data)","preventionTips":["Keep converter choice explicit per input type","Avoid passing polars/arrow objects back into from_pandas","Add type asserts at module boundaries"],"tags":["python","polars","pandas","type-error"],"backgroundTag":"invalid-argument-value","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"}