pandas-dev/pandas · error · TypeError
You cannot access the property {name}
Error message
You cannot access the property {name} What it means
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.
Source
Thrown at pandas/core/accessor.py:67
"""
Provide method name lookup and completion.
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:
"""View on GitHub (pinned to 71959b8cb9)
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.
Example fix
# before s = pd.Series(['a', 'b']) s.dt.year # .dt delegated property not valid for strings # after s = pd.to_datetime(s) s.dt.year
Defensive patterns
Strategy: validation
Validate before calling
def safe_accessor_attr(s, accessor, attr):
import pandas.api.types as pt
ok = (accessor == 'dt' and pt.is_datetime64_any_dtype(s)) or \
(accessor == 'str' and s.dtype == object) or \
(accessor == 'cat' and isinstance(s.dtype, pd.CategoricalDtype))
if not ok:
raise AttributeError(f'{accessor} not valid for dtype {s.dtype}')
return getattr(getattr(s, accessor), attr) Type guard
def supports_dt(s) -> bool:
import pandas.api.types as pt
return pt.is_datetime64_any_dtype(s) or pt.is_timedelta64_dtype(s) Try / catch
try:
val = s.dt.year
except TypeError:
val = pd.to_datetime(s).dt.year Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The property {name} cannot be set
- You cannot call method {name}
- Can only use .cat accessor with a 'category' dtype
- The numba engine only supports using string or numeric colum
- bins argument only works with numeric data.
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/be5cfbc386e6b775.
Report an issue: GitHub.