pandas-dev/pandas · error · TypeError

You cannot call method {name}

Error message

You cannot call method {name}

What it means

Raised by the base PandasDelegate._delegate_method fallback. When a method is wired onto a host class through @delegate_names but the concrete accessor never overrides _delegate_method, invoking it hits this generic TypeError. It signals that the delegated method is not implemented for the object/dtype.

Source

Thrown at pandas/core/accessor.py:73

        """
        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
        ----------
        cls
            Class to add the methods/properties to.

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Verify the dtype matches the accessor's requirements (string/object for .str, datetime for .dt, categorical for .cat).
  2. If you own the accessor, implement _delegate_method to provide the behavior.
  3. Use the equivalent top-level pandas function instead of the delegated method.

Example fix

# before
s = pd.Series([1, 2, 3])
s.str.upper()  # .str delegated method not valid for ints
# after
s = s.astype(str)
s.str.upper()
Defensive patterns

Strategy: validation

Validate before calling

def call_delegated(s, accessor, method, *a, **k):
    import pandas.api.types as pt
    if accessor == 'str' and s.dtype != object:
        s = s.astype(str)
    return getattr(getattr(s, accessor), method)(*a, **k)

Type guard

def supports_str(s) -> bool:
    return s.dtype == object or str(s.dtype) == 'string'

Try / catch

try:
    return s.str.upper()
except TypeError:
    return s.astype(str).str.upper()

Prevention

When it happens

Trigger: Calling a delegated accessor method (one declared via delegate_names(..., typ='method')) on an object whose accessor subclass did not implement _delegate_method; invoking a dtype-specific method on data of an incompatible dtype through the delegate path.

Common situations: Custom accessor that registered method names but left the dispatch unimplemented; calling a categorical/string accessor method on a non-matching dtype; version drift where a delegated method was renamed.

Related errors


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