pandas-dev/pandas · error · TypeError

The property {name} cannot be set

Error message

The property {name} cannot be set

What it means

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.

Source

Thrown at pandas/core/accessor.py:70

        Notes
        -----
        Only provide 'public' methods.
        """
        rv = set(super().__dir__())
        rv = (rv - self._dir_deletions()) | self._dir_additions()
        return sorted(rv)


class PandasDelegate:
    """
    Abstract base class for delegating methods/properties.
    """

    def _delegate_property_get(self, name: str, *args, **kwargs):
        raise TypeError(f"You cannot access the property {name}")

    def _delegate_property_set(self, name: str, value, *args, **kwargs) -> None:
        raise TypeError(f"The property {name} cannot be set")

    def _delegate_method(self, name: str, *args, **kwargs):
        raise TypeError(f"You cannot call method {name}")

    @classmethod
    def _add_delegate_accessors(
        cls,
        delegate,
        accessors: list[str],
        typ: str,
        overwrite: bool = False,
        accessor_mapping: Callable[[str], str] = lambda x: x,
        raise_on_missing: bool = True,
    ) -> None:
        """
        Add accessors to cls from the delegate class.

        Parameters

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Mutate the underlying data directly and reconstruct the object instead of assigning through the accessor property.
  2. If authoring the accessor, implement _delegate_property_set or a real setter via @property.
  3. Verify the attribute is meant to be writable for the current dtype.

Example fix

# before
cat = pd.Categorical(['a', 'b'])
cat.categories = ['x', 'y']  # delegated setter not implemented
# after
cat = cat.rename_categories(['x', 'y'])
Defensive patterns

Strategy: validation

Validate before calling

def assign_via_method(obj, prop, value):
    if not hasattr(type(obj), prop) or not isinstance(
        getattr(type(obj), prop), property
    ) or getattr(type(obj), prop).fset is None:
        raise AttributeError(f'{prop} is read-only; use the corresponding method')
    setattr(obj, prop, value)

Type guard

def is_settable(obj, prop) -> bool:
    p = getattr(type(obj), prop, None)
    return isinstance(p, property) and p.fset is not None

Try / catch

try:
    obj.prop = value
except TypeError:
    obj = obj.some_mutating_method(value)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/4711ad622fa436b8. Report an issue: GitHub.