{"record":{"id":"4814e66354e3e9a1","repo":"pola-rs/polars","slug":"cannot-override-reserved-namespace-name-r","errorCode":null,"errorMessage":"cannot override reserved namespace {name!r}","messagePattern":"cannot override reserved namespace (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/api.py","lineNumber":56,"sourceCode":"\n    def __get__(self, instance: NS | None, cls: type[NS]) -> NS | type[NS]:\n        if instance is None:\n            return self._ns\n\n        ns_instance = self._ns(instance)  # type: ignore[call-arg]\n        setattr(instance, self._accessor, ns_instance)\n        return ns_instance\n\n\ndef _create_namespace(\n    name: str, cls: type[Expr | DataFrame | LazyFrame | Series]\n) -> Callable[[type[NS]], type[NS]]:\n    \"\"\"Register custom namespace against the underlying Polars class.\"\"\"\n\n    def namespace(ns_class: type[NS]) -> type[NS]:\n        if name in _reserved_namespaces:\n            msg = f\"cannot override reserved namespace {name!r}\"\n            raise AttributeError(msg)\n        elif (attr := getattr(cls, name, None)) is not None:\n            if isfunction(attr) or isinstance(attr, property) or name.startswith(\"_\"):\n                msg = f\"cannot override `{cls.__name__}.{name}` with custom namespace {ns_class.__name__!r}\"\n                raise AttributeError(msg)\n            warn(\n                f\"overriding existing custom namespace {name!r} (on {cls.__name__})\",\n                UserWarning,\n                stacklevel=find_stacklevel(),\n            )\n\n        setattr(cls, name, NameSpace(name, ns_class))\n        cls._accessors.add(name)\n        return ns_class\n\n    return namespace\n\n\ndef register_expr_namespace(name: str) -> Callable[[type[NS]], type[NS]]:","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/api.py#L38-L74","documentation":"AttributeError from _create_namespace's inner decorator (py-polars/src/polars/api.py:53-56). register_expr/dataframe/lazyframe/series_namespace validate the chosen name against _reserved_namespaces, which is the union of _accessors already registered on polars' own classes ('str', 'dt', 'cat', 'list', 'name', 'meta', 'string', 'temporal', 'cat', 'list', 'struct', ...). Decorating with one of these names tries to shadow a built-in polars namespace and is hard-rejected.","triggerScenarios":"@pl.register_series_namespace('str'), @pl.register_dataframe_namespace('dt'), or any decorator name that equals an existing polars accessor found in cls._accessors.","commonSituations":"Writing a generic plugin library that picks namespace names like 'str' or 'dt' because they feel natural; name collisions between an extension package and polars' own namespaces added in newer releases.","solutions":["Pick a distinct namespace name, e.g. 'geo', 'text', 'mylib'","Prefix extension namespaces with a short project prefix to avoid collisions","If migrating old code, update all call sites from df.<old>() to df.<new>()"],"exampleFix":"# before\n@pl.register_series_namespace('str')\nclass StrExt: ...\n\n# after\n@pl.register_series_namespace('text')\nclass StrExt: ...","handlingStrategy":"validation","validationCode":"import polars as pl\n\ndef namespace_name_ok(name: str, cls) -> bool:\n    return not hasattr(cls, name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check hasattr(pl.DataFrame, name) / hasattr(pl.Series, name) before registering","Prefix custom namespaces with a project-specific token ('geo', 'mylib_')","Never register 'str', 'dt', 'cat', 'list', 'struct', 'meta', 'name' — they are reserved"],"tags":["polars","register-namespace","reserved-name","attributeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}