{"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":741,"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":723,"sourceCodeEnd":757,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/various.py#L723-L757","documentation":"Polars' `require_same_type` guard raises TypeError when an operation is given an `other` argument whose Python class differs from `current` (e.g. passing a DataFrame where a LazyFrame is expected, or vice versa). The message names both qualified types so the mismatch is obvious. It is a fail-fast check for API misuse that would otherwise surface as confusing Rust-side panics.","triggerScenarios":"Calling `df.equals(other)`, `lf.join(other, ...)`, `join_asof`, `join_where`, `df.vstack(other)`, or `df.extend(other)` where `other` is not an instance of the same class (or a subclass/superclass relationship) as the receiver.","commonSituations":"Mixing DataFrame and LazyFrame objects after an accidental `.lazy()` or `.collect()`; passing a PyArrow table or Pandas DataFrame instead of a Polars object; holding a mock or subclass wrapper in tests.","solutions":["Check `type(other)` and convert it: wrap in `.lazy()` for LazyFrame parameters or call `.collect()` for DataFrame parameters","Ensure you imported and constructed the correct Polars class (DataFrame vs LazyFrame)","If `other` comes from another library, convert first (e.g. `pl.from_pandas(pdf)`, `pl.from_arrow(tbl)`)"],"exampleFix":"// before\nlf.join(other_df, on=\"id\")  # TypeError: expected LazyFrame, not DataFrame\n// after\nlf.join(other_df.lazy(), on=\"id\")","handlingStrategy":"type-guard","validationCode":"assert isinstance(other, type(df)), f\"expected {type(df).__name__}, got {type(other).__name__}\"","typeGuard":"def is_same_polars_type(current: object, other: object) -> bool:\n    return isinstance(other, type(current)) or isinstance(current, type(other))","tryCatchPattern":"try:\n    result = df.join(other, on=\"id\")\nexcept TypeError as e:\n    if \"expected `other`\" in str(e):\n        other = other.lazy() if isinstance(df, pl.LazyFrame) else other.collect()\n        result = df.join(other, on=\"id\")\n    else:\n        raise","preventionTips":["Normalize inputs at API boundaries (call .lazy() or .collect() explicitly)","Type-annotate functions with pl.DataFrame/pl.LazyFrame so mypy/pyright flag mismatches","Avoid mixing eager and lazy objects in the same code path"],"tags":["python","type-error","api-misuse"],"backgroundTag":"type-mismatch","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"}