{"record":{"id":"c850d7324b139fa8","repo":"pandas-dev/pandas","slug":"you-cannot-call-method-name","errorCode":null,"errorMessage":"You cannot call method {name}","messagePattern":"You cannot call method (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/accessor.py","lineNumber":73,"sourceCode":"        \"\"\"\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\n        ----------\n        cls\n            Class to add the methods/properties to.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/accessor.py#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the dtype matches the accessor's requirements (string/object for .str, datetime for .dt, categorical for .cat).","If you own the accessor, implement _delegate_method to provide the behavior.","Use the equivalent top-level pandas function instead of the delegated method."],"exampleFix":"# before\ns = pd.Series([1, 2, 3])\ns.str.upper()  # .str delegated method not valid for ints\n# after\ns = s.astype(str)\ns.str.upper()","handlingStrategy":"validation","validationCode":"def call_delegated(s, accessor, method, *a, **k):\n    import pandas.api.types as pt\n    if accessor == 'str' and s.dtype != object:\n        s = s.astype(str)\n    return getattr(getattr(s, accessor), method)(*a, **k)","typeGuard":"def supports_str(s) -> bool:\n    return s.dtype == object or str(s.dtype) == 'string'","tryCatchPattern":"try:\n    return s.str.upper()\nexcept TypeError:\n    return s.astype(str).str.upper()","preventionTips":["Match the accessor to the dtype (.str for object/string, .dt for datetime).","Override _delegate_method when building custom accessors.","Use top-level pandas functions as a fallback for delegated methods."],"tags":["accessor","delegate","method","dtype"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}