{"record":{"id":"591e84326e2f53c5","repo":"pola-rs/polars","slug":"expected-other-to-be-a-qualified-type-name-curr","errorCode":null,"errorMessage":"expected `other` to be a {qualified_type_name(current)!r}, not {qualified_type_name(other)!r}","messagePattern":"expected `other` to be a (.+?), not (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/various.py","lineNumber":744,"sourceCode":"def require_same_type(current: Any, other: Any) -> None:\n    \"\"\"\n    Raise an error if the two arguments are not of the same type.\n\n    The check will not raise an error if one object is of a subclass of the other.\n\n    Parameters\n    ----------\n    current\n        The object the type of which is being checked against.\n    other\n        An object that has to be of the same type.\n    \"\"\"\n    if not isinstance(other, type(current)) and not isinstance(current, type(other)):\n        msg = (\n            f\"expected `other` to be a {qualified_type_name(current)!r}, \"\n            f\"not {qualified_type_name(other)!r}\"\n        )\n        raise TypeError(msg)\n\n\nclass _NamespaceSuggestMixin:\n    \"\"\"Mixin that adds suggestions to AttributeError on namespace typos.\"\"\"\n\n    def __getattr__(self, name: str) -> NoReturn:\n        import difflib\n\n        public = [m for m in dir(type(self)) if not m.startswith(\"_\")]\n        matches = difflib.get_close_matches(name, public, n=1, cutoff=0.6)\n        if matches:\n            msg = f\"'{type(self).__name__}' object has no attribute {name!r}. Did you mean: {matches[0]!r}?\"\n        else:\n            msg = f\"'{type(self).__name__}' object has no attribute {name!r}\"\n        raise AttributeError(msg)\n","sourceCodeStart":726,"sourceCodeEnd":760,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/various.py#L726-L760","documentation":"TypeError from require_same_type (py-polars/src/polars/_utils/various.py:726-744). Binary frame/series methods that mutate or combine with an `other` object (DataFrame.update, vstack/extend, Series.__iadd__-style in-place ops, LazyFrame.update/join-ish helpers — 18 call sites across frame.py, series.py, lazyframe/frame.py) require `other` to be the same type as `self` (subclass relationships allowed in either direction). Passing e.g. a pandas DataFrame, dict, list, or numpy array where a polars DataFrame/Series is required raises this with both qualified type names.","triggerScenarios":"df.update(pandas_df); df_polars.vstack([row_dict]); series.extend([1, 2, 3]); lf.update(other_df) where other_df is a DataFrame instead of LazyFrame (or vice versa on the wrong call site).","commonSituations":"Mixed pandas/polars codebases where a variable's provenance changed; wrapping polars objects in custom containers; passing a dict of columns where a constructed frame is expected.","solutions":["Convert before the call: pl.DataFrame(pandas_df) or pl.Series(values)","Match lazy vs eager: lf.update(other.collect()) or keep both lazy","Use the APIs designed for raw inputs (pl.DataFrame(dict), df.insert_column) instead of the binary `other` methods"],"exampleFix":"# before\ndf.update(pandas_df)  # TypeError: expected `other` to be a 'DataFrame'\n\n# after\ndf.update(pl.DataFrame(pandas_df))","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import polars as pl\n\ndef is_polars_frame(o: object) -> bool:\n    return isinstance(o, (pl.DataFrame, pl.LazyFrame, pl.Series))\n\ndef require_frame(o: object) -> pl.DataFrame:\n    if not isinstance(o, pl.DataFrame):\n        raise TypeError(f'expected DataFrame, got {type(o).__name__}')\n    return o","tryCatchPattern":"try:\n    df.update(other)\nexcept TypeError as e:\n    if 'expected `other`' in str(e):\n        import polars as pl\n        df = df.update(pl.DataFrame(other))\n    else:\n        raise","preventionTips":["Convert foreign objects (pandas, dicts, lists) to the exact polars type before binary methods","Keep lazy/eager pairs consistent on both sides of update/extend/vstack-style calls","Type-annotate boundaries so mismatches surface at lint time"],"tags":["polars","type-mismatch","update","typeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}