{"record":{"id":"42ef84035c53abfe","repo":"pola-rs/polars","slug":"type-self-name-object-has-no-attribute-n-42ef84","errorCode":null,"errorMessage":"'{type(self).__name__}' object has no attribute {name!r}","messagePattern":"'(.+?)' object has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/various.py","lineNumber":756,"sourceCode":"            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":738,"sourceCodeEnd":757,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/various.py#L738-L757","documentation":"This AttributeError is raised by `_NamespaceSuggestMixin.__getattr__`, a mixin installed on Polars namespaces, when accessing an attribute that does not exist. If difflib finds a close match among the public methods, the message appends 'Did you mean: ...' to suggest the intended name. It replaces the default AttributeError to give typo-friendly diagnostics.","triggerScenarios":"Typing a misspelled namespace method, e.g. `df.str.toupper()` instead of `to_uppercase`, or `s.dt.days_in_month()` instead of `month_start`-style names, on any str/dt/etc. namespace object.","commonSituations":"Upgrading Polars after a method rename; mixing up camelCase/snake_case conventions from other libraries (pandas, spark); autocomplete not used in notebooks.","solutions":["Read the 'Did you mean' hint in the message and use the suggested attribute","Run `dir(obj)` or check the Polars API docs for the correct method name","Pin/align your code with the Polars version's API reference when upgrading"],"exampleFix":"// before\ndf.select(pl.col(\"a\").str.tolower())  # AttributeError, Did you mean: 'to_lowercase'?\n// after\ndf.select(pl.col(\"a\").str.to_lowercase())","handlingStrategy":"type-guard","validationCode":"if not hasattr(ns, \"to_lowercase\"):\n    print([m for m in dir(ns) if not m.startswith('_')])","typeGuard":"def has_ns_method(ns: object, name: str) -> bool:\n    return not name.startswith('_') and callable(getattr(type(ns), name, None))","tryCatchPattern":"try:\n    out = df.select(pl.col('a').str.tolower())\nexcept AttributeError as e:\n    if 'object has no attribute' in str(e):\n        logging.warning(\"namespace typo: %s\", e)  # message includes 'Did you mean'\n    else:\n        raise","preventionTips":["Use IDE autocomplete/IPython tab-completion on namespace objects","Run mypy or pyright against polars-stubs to catch bad attribute names statically","After upgrading polars, grep for renamed namespace methods against the changelog"],"tags":["python","attribute-error","typo"],"backgroundTag":"invalid-identifier","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"}