pola-rs/polars · error · AttributeError

' ' object has no attribute . Did you mean: ?

Error message

'{type(self).__name__}' object has no attribute {name!r}. Did you mean: {matches[0]!r}?

What it means

Raised from `_NamespaceSuggestMixin.__getattr__` when a namespace object is accessed with an attribute name it does not define. It is an enhanced AttributeError: difflib found a close public-attribute match, so the message includes a 'Did you mean' suggestion for the typo.

Solutions

  1. Use the suggested attribute name shown after 'Did you mean'.

Example fix

getattr(obj, matches[0])
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Attribute access with a typo; a close match exists.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@5d8ebabf11 (2026-08-19). Data as JSON: /api/errors/6671f98d08e24162. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/_utils/various.py:756

            f"expected `other` to be a {qualified_type_name(current)!r}, "
            f"not {qualified_type_name(other)!r}"
        )
        raise TypeError(msg)


class _NamespaceSuggestMixin:
    """Mixin that adds suggestions to AttributeError on namespace typos."""

    def __getattr__(self, name: str) -> NoReturn:
        import difflib

        public = [m for m in dir(type(self)) if not m.startswith("_")]
        matches = difflib.get_close_matches(name, public, n=1, cutoff=0.6)
        if matches:
            msg = f"'{type(self).__name__}' object has no attribute {name!r}. Did you mean: {matches[0]!r}?"
        else:
            msg = f"'{type(self).__name__}' object has no attribute {name!r}"
        raise AttributeError(msg)

View on GitHub (pinned to 5d8ebabf11)