{"record":{"id":"6671f98d08e24162","repo":"pola-rs/polars","slug":"type-self-name-object-has-no-attribute-n","errorCode":null,"errorMessage":"'{type(self).__name__}' object has no attribute {name!r}. Did you mean: {matches[0]!r}?","messagePattern":"'(.+?)' object has no attribute (.+?)\\. Did you mean: (.+?)\\?","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/various.py","lineNumber":759,"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":741,"sourceCodeEnd":760,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/various.py#L741-L760","documentation":"AttributeError from _NamespaceSuggestMixin.__getattr__ (py-polars/src/polars/_utils/various.py:749-759) when a misspelled attribute is accessed on a polars namespace object (the objects behind df.str, df.dt, etc.) and difflib.get_close_matches finds a near match (cutoff 0.6) among public attributes. The message names the class and suggests the closest attribute, e.g. \"'StringNameSpace' object has no attribute 'strip_chars'. Did you mean: 'strip'?\"","triggerScenarios":"Typos on namespace objects: s.str.to_lowercas(), s.dt.truncate_date(), s.list.eval_first(); renamed methods after a polars upgrade (old names no longer exist but fuzzy-match the new one).","commonSituations":"Upgrading polars across breaking releases where methods were renamed (the suggestion usually points at the new name); IDE-less editing; stale StackOverflow snippets.","solutions":["Apply the suggested attribute from the message","Check the namespace's real API with dir(df.str) or help","After upgrades, grep the changelog for renames of the failing method"],"exampleFix":"# before\ns.str.to_lowercas()  # AttributeError: Did you mean: 'to_lowercase'?\n\n# after\ns.str.to_lowercase()","handlingStrategy":"type-guard","validationCode":"import polars as pl\n\ndef has_attr(obj: object, name: str) -> bool:\n    return name in dir(obj)","typeGuard":"def valid_ns_method(ns: object, name: str) -> bool:\n    return not name.startswith('_') and callable(getattr(type(ns), name, None))","tryCatchPattern":"try:\n    out = s.str.to_lowercas()\nexcept AttributeError as e:\n    msg = str(e)\n    if 'Did you mean' in msg:\n        import re\n        fix = re.search(r\"Did you mean: '([^']+)'\", msg).group(1)\n        out = getattr(s.str, fix)()\n    else:\n        raise","preventionTips":["Read the suggestion in the message — it usually names the correct method","After polars upgrades, check the changelog for renamed namespace methods","Use dir() or the API docs instead of guessing method names"],"tags":["polars","namespace","typo","attributeerror","did-you-mean"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}