{"record":{"id":"4711ad622fa436b8","repo":"pandas-dev/pandas","slug":"the-property-name-cannot-be-set","errorCode":null,"errorMessage":"The property {name} cannot be set","messagePattern":"The property (.+?) cannot be set","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/accessor.py","lineNumber":70,"sourceCode":"        Notes\n        -----\n        Only provide 'public' methods.\n        \"\"\"\n        rv = set(super().__dir__())\n        rv = (rv - self._dir_deletions()) | self._dir_additions()\n        return sorted(rv)\n\n\nclass PandasDelegate:\n    \"\"\"\n    Abstract base class for delegating methods/properties.\n    \"\"\"\n\n    def _delegate_property_get(self, name: str, *args, **kwargs):\n        raise TypeError(f\"You cannot access the property {name}\")\n\n    def _delegate_property_set(self, name: str, value, *args, **kwargs) -> None:\n        raise TypeError(f\"The property {name} cannot be set\")\n\n    def _delegate_method(self, name: str, *args, **kwargs):\n        raise TypeError(f\"You cannot call method {name}\")\n\n    @classmethod\n    def _add_delegate_accessors(\n        cls,\n        delegate,\n        accessors: list[str],\n        typ: str,\n        overwrite: bool = False,\n        accessor_mapping: Callable[[str], str] = lambda x: x,\n        raise_on_missing: bool = True,\n    ) -> None:\n        \"\"\"\n        Add accessors to cls from the delegate class.\n\n        Parameters","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/accessor.py#L52-L88","documentation":"Raised by the base PandasDelegate._delegate_property_set fallback. The delegate machinery rejects assignment to a delegated property when the concrete accessor has not implemented _delegate_property_set for that name. It indicates the property is read-only on this object or not implemented for this dtype.","triggerScenarios":"Assigning to a delegated accessor property (e.g. setting a categorical/str/dt delegated attribute) whose accessor subclass did not override _delegate_property_set; assigning to a property exposed only for reading on the given dtype.","commonSituations":"Trying to mutate an accessor-managed property that is computed/derived rather than backed by storage; porting code that set an attribute under an older pandas where it was writable; custom accessor that declared a property but no setter.","solutions":["Mutate the underlying data directly and reconstruct the object instead of assigning through the accessor property.","If authoring the accessor, implement _delegate_property_set or a real setter via @property.","Verify the attribute is meant to be writable for the current dtype."],"exampleFix":"# before\ncat = pd.Categorical(['a', 'b'])\ncat.categories = ['x', 'y']  # delegated setter not implemented\n# after\ncat = cat.rename_categories(['x', 'y'])","handlingStrategy":"validation","validationCode":"def assign_via_method(obj, prop, value):\n    if not hasattr(type(obj), prop) or not isinstance(\n        getattr(type(obj), prop), property\n    ) or getattr(type(obj), prop).fset is None:\n        raise AttributeError(f'{prop} is read-only; use the corresponding method')\n    setattr(obj, prop, value)","typeGuard":"def is_settable(obj, prop) -> bool:\n    p = getattr(type(obj), prop, None)\n    return isinstance(p, property) and p.fset is not None","tryCatchPattern":"try:\n    obj.prop = value\nexcept TypeError:\n    obj = obj.some_mutating_method(value)","preventionTips":["Prefer explicit methods (rename_categories, astype) over assigning accessor properties.","Implement setters when authoring accessors via @property.","Treat accessor properties as read-only unless documented otherwise."],"tags":["accessor","delegate","property","assignment"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}