pandas-dev/pandas · error · AttributeError

' ' does not have duration components

Error message

'{self.dtype}' does not have duration components

What it means

Raised by ArrowExtensionArray._duration_unit (an AttributeError, not ValueError) when the array's pyarrow type is not a `duration` type. The duration-component accessors (_dt_day_remainder, _dt_days, _dt_seconds, etc.) depend on it; by raising AttributeError the `.dt` dispatcher converts this into the standard 'dt.<name> is not supported for <dtype>' message, preventing the underlying int64 from being silently interpreted as a duration.

Solutions

  1. Ensure the Series actually holds durations: compute a difference first, e.g. `ser = end_ts - start_ts`, so the dtype becomes duration[pyarrow].
  2. If you wanted calendar components of a timestamp, use the timestamp-specific accessors (`.dt.day`, `.dt.hour`) instead of `.dt.days`.

Example fix

# before
ts.dt.days            # ts is timestamp[pyarrow]
# after
(ts - ts.iloc[0]).dt.days   # duration[pyarrow]
Defensive patterns

Strategy: validation

Validate before calling

import pyarrow as pa
pa_type = ser.dtype.pyarrow_dtype
if not pa.types.is_duration(pa_type):
    raise AttributeError(f"{ser.dtype} has no duration components; compute a delta first")
ser.dt.days

Type guard

def is_arrow_duration(ser) -> bool:
    import pyarrow as pa
    return hasattr(ser.dtype, "pyarrow_dtype") and pa.types.is_duration(ser.dtype.pyarrow_dtype)

Try / catch

try:
    out = ser.dt.days
except AttributeError:
    out = (ser - ser.iloc[0]).dt.days   # construct a duration

Prevention

When it happens

Trigger: Calling a duration-only component like `ser.dt.days`, `ser.dt.seconds`, or `ser.dt.microseconds` on a Series whose dtype is a pyarrow timestamp (timestamp[pyarrow]) or date rather than a duration[pyarrow].

Common situations: Subtracting two timestamps produces a duration, but operating directly on a timestamp column with `.dt.days`; confusing timedelta semantics with timestamp semantics on arrow dtypes.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/1483e41519e3be0a. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/arrays/arrow/array.py:3830

                pa.scalar(None, type=pa.int32()),
                pa.scalar(0, type=pa.int32()),
            )
        )

    @property
    def _duration_unit(self) -> str:
        """
        Return the time unit for a duration-typed array.

        Raises ``AttributeError`` for non-duration dtypes so the duration
        component accessors (``_dt_days``, ``_dt_seconds``, etc.) are rejected
        for e.g. ``timestamp[pyarrow]`` instead of silently treating the
        underlying int64 as a duration. The ``dt`` dispatcher turns this into
        the usual "dt.<name> is not supported for <dtype>" error.
        """
        pa_type = self._pa_array.type
        if not pa.types.is_duration(pa_type):
            raise AttributeError(f"'{self.dtype}' does not have duration components")
        return pa_type.unit

    @cache_readonly
    def _dt_day_remainder(self) -> pa.ChunkedArray:
        """
        Return the remainder after removing full days, always non-negative.

        For negative durations like -22h 57m 57s (= -1 day + 1h 2m 3s),
        this returns the positive offset from the day boundary.

        This is cached because it's used by all sub-day component accessors.
        """
        unit = self._duration_unit
        divisor = _DURATION_DIVISORS["day"][unit]
        arr = self._pa_array.cast(pa.int64())
        days = floor_div_int64(arr, divisor)
        # remainder = arr - days * divisor (always non-negative)
        return pc.subtract(arr, pc.multiply(days, divisor))

View on GitHub (pinned to 3b7651241d)