{"record":{"id":"83f9fe32bba9b96d","repo":"pola-rs/polars","slug":"type-self-name-r-object-has-no-attribute-n","errorCode":null,"errorMessage":"{type(self).__name__!r} object has no attribute {name!r}","messagePattern":"(.+?) object has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/utils.py","lineNumber":101,"sourceCode":"    \"\"\"\n    original_getattr = getattr(cls, \"__getattr__\", None)\n\n    def __getattr__(self: Any, name: str) -> Any:\n        # note: a dummy Expr suffices; we only want the namespace's __getattr__\n        expr: Any = pl.Expr()\n        expr._pyexpr = None\n        if namespace is not None:\n            expr = getattr(expr, namespace)\n        try:\n            return expr.__getattr__(name)\n        except AttributeRemovedError:\n            raise\n        except AttributeError:\n            if original_getattr is not None:\n                return original_getattr(self, name)\n            else:\n                msg = f\"{type(self).__name__!r} object has no attribute {name!r}\"\n                raise AttributeError(msg, name=name, obj=self) from None\n\n    return __getattr__\n\n\ndef _expr_lookup(namespace: str | None) -> set[tuple[str | None, str, tuple[str, ...]]]:\n    \"\"\"Create lookup of potential Expr methods (in the given namespace).\"\"\"\n    # dummy Expr object that we can introspect\n    expr = pl.Expr()\n    expr._pyexpr = None  # type: ignore[assignment]\n\n    # optional indirection to \"expr.str\", \"expr.dt\", etc\n    if namespace is not None:\n        expr = getattr(expr, namespace)\n\n    lookup = set()\n    for name in dir(expr):\n        if not name.startswith(\"_\") or name == \"__getattr__\":\n            try:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/pola-rs/polars/blob/5d8ebabf11caea54a5c29178a64a058762f49766/py-polars/src/polars/series/utils.py#L83-L119","documentation":"This is the __getattr__ generated by polars.series.utils (used to build Series namespaces like str, dt, cat): when an attribute is not found on the Series object and no original __getattr__ handles it, Polars raises AttributeError with a helpful message. It is the standard Python 'attribute not found' error surfaced through a dynamically-constructed accessor chain.","triggerScenarios":"Accessing any nonexistent attribute or misspelled method on a Series, e.g. s.str.lowercse(), s.dt.datetrunc('1d'), or an attribute that only exists on a different dtype namespace (s.cat on a non-Categorical series).","commonSituations":"Typos in chained expressions; calling Expr-only methods on Series (or vice versa); using namespace methods on the wrong dtype (str methods on numeric series); version changes that renamed/moved Series methods.","solutions":["Check the misspelling against the Polars API docs for the relevant namespace (str/dt/cat/list)","Verify the Series dtype matches the namespace you're calling (use s.dtype; cast with .cast(pl.Utf8) etc. if needed)","If the method exists only on Expr, convert: pl.select(F.lit(s).<method>()) or use the equivalent Series-level API","Check the Polars changelog if the method was renamed/moved in an upgrade"],"exampleFix":"# before\ns.str.lowercse()\n\n# after\ns.str.to_lowercase()","handlingStrategy":"validation","validationCode":"# before calling a namespace method, confirm it exists\nassert hasattr(s.str, 'to_lowercase'), 'method missing on str namespace'","typeGuard":"from polars import Series\n\ndef has_namespace(s: Series, ns: str) -> bool:\n    return {pl.String: 'str', pl.Datetime: 'dt', pl.Categorical: 'cat'}.get(s.dtype, None) == ns","tryCatchPattern":"try:\n    out = s.str.to_lowercase()\nexcept AttributeError as e:\n    raise ValueError(f\"bad Series operation on dtype {s.dtype}: {e}\") from e","preventionTips":["Check s.dtype before using dtype-specific namespaces","Use an IDE/linter with polars stubs to catch misspelled methods statically","Run small smoke tests on chained Series expressions after Polars upgrades"],"tags":["polars","series","attributeerror","typo","dtype-namespace","getattr"],"backgroundTag":"polars-series-attribute-not-found","analyzedSha":"5d8ebabf11caea54a5c29178a64a058762f49766","analyzedAt":"2026-08-28T18:02:35.179Z","contentChangedAt":"2026-08-28T18:02:35.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}