{"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":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) for a missing attribute on a polars namespace object where no close match exists (difflib cutoff 0.6 not met). The message is the plain \"'<Class>' object has no attribute '<name>'\" with no suggestion, meaning the name is not a near-miss of any public method on that namespace.","triggerScenarios":"Calling methods that never existed on that namespace: df.str.pivot(...), s.dt.group_by(...); calling a DataFrame-level or Series-level method on the wrong sub-namespace; using a method from a different polars version.","commonSituations":"Assuming a method lives in a namespace it does not (e.g. window functions under .str); code written against a different polars version; tabs/autocomplete guessing.","solutions":["Look up the correct home of the method: dir(obj), help(obj), or the API docs for that namespace","Call the method on the parent object if it is not namespace-scoped, e.g. df.pivot() not df.str.pivot()","Upgrade/downgrade polars to the version whose API you are coding against"],"exampleFix":"# before\ndf.str.pivot(on='x')  # AttributeError, no suggestion\n\n# after\ndf.pivot(on='x')","handlingStrategy":"type-guard","validationCode":"import polars as pl\n\ndef method_exists(obj: object, name: str) -> bool:\n    return hasattr(obj, name)","typeGuard":"def ns_has(ns: object, name: str) -> bool:\n    return name in dir(type(ns))","tryCatchPattern":null,"preventionTips":["Verify which object owns the method: DataFrame/Series level vs .str/.dt/.list namespaces","Pin a polars version in lockstep with the API you code against","Use static typing/IDE completion for polars objects to catch bad names pre-run"],"tags":["polars","namespace","attributeerror","missing-attribute"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}