{"record":{"id":"be5cfbc386e6b775","repo":"pandas-dev/pandas","slug":"you-cannot-access-the-property-name","errorCode":null,"errorMessage":"You cannot access the property {name}","messagePattern":"You cannot access the property (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/accessor.py","lineNumber":67,"sourceCode":"        \"\"\"\n        Provide method name lookup and completion.\n\n        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        \"\"\"","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/accessor.py#L49-L85","documentation":"Raised by the base PandasDelegate._delegate_property_get fallback. Accessor classes built with @delegate_names declare properties that the host object should delegate; when a concrete accessor has not actually implemented _delegate_property_get for a given name, the base implementation rejects the read with this TypeError. In practice it signals that a delegated property is not supported on the object/dtype in question.","triggerScenarios":"Accessing a delegated accessor property (e.g. a property wired through delegate_names on a categorical/datetime/string accessor) on an object whose accessor subclass left _delegate_property_get un-overridden for that name; accessing an accessor-only attribute on an incompatible dtype via the delegate machinery.","commonSituations":"Subclassing a pandas accessor and forgetting to override the delegate get/set hooks; calling an accessor property that is only meaningful for a specific dtype on data of another dtype; version changes that rename or relocate delegated properties.","solutions":["Confirm the Series/Index dtype actually supports the accessor (e.g. .dt needs datetime-like, .str needs string/object).","If you authored the accessor, override _delegate_property_get to implement the property.","Switch to the correct accessor or convert the data to a supported dtype before accessing the property."],"exampleFix":"# before\ns = pd.Series(['a', 'b'])\ns.dt.year  # .dt delegated property not valid for strings\n# after\ns = pd.to_datetime(s)\ns.dt.year","handlingStrategy":"validation","validationCode":"def safe_accessor_attr(s, accessor, attr):\n    import pandas.api.types as pt\n    ok = (accessor == 'dt' and pt.is_datetime64_any_dtype(s)) or \\\n         (accessor == 'str' and s.dtype == object) or \\\n         (accessor == 'cat' and isinstance(s.dtype, pd.CategoricalDtype))\n    if not ok:\n        raise AttributeError(f'{accessor} not valid for dtype {s.dtype}')\n    return getattr(getattr(s, accessor), attr)","typeGuard":"def supports_dt(s) -> bool:\n    import pandas.api.types as pt\n    return pt.is_datetime64_any_dtype(s) or pt.is_timedelta64_dtype(s)","tryCatchPattern":"try:\n    val = s.dt.year\nexcept TypeError:\n    val = pd.to_datetime(s).dt.year","preventionTips":["Check dtype before using dtype-specific accessors.","Convert columns with pd.to_datetime / astype before .dt/.str/.cat.","When subclassing accessors, override _delegate_property_get."],"tags":["accessor","delegate","dtype","property"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}