pandas-dev/pandas · error · TypeError

DateOffset {other} is intra-day and cannot be applied to dat

Error message

DateOffset {other} is intra-day and cannot be applied to date32/date64 arrays

What it means

Raised by _arith_method when adding/subtracting a BaseOffset (DateOffset) to a pyarrow date32/date64 array and the offset produces intra-day (non-midnight) timestamps. The code casts dates to timestamp[us], applies the offset via DatetimeArray, then checks is_normalized; if the result has a time component it cannot be represented back as a pure date, so pandas raises TypeError.

Source

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

        result = np.empty(len(self), dtype=object)
        result[mask] = self.dtype.na_value
        result[valid] = op(np.asarray(self, dtype=object)[valid], other)

        if not lib.is_string_array(result, skipna=True):
            return result
        return type(self)._from_sequence(result, dtype=self.dtype)

    def _arith_method(self, other, op) -> Self | npt.NDArray[np.object_]:
        if isinstance(other, BaseOffset) and pa.types.is_date(self._pa_array.type):
            # Cast date32/date64 → timestamp, apply offset via DatetimeArray, cast back
            ts_array = type(self)(self._pa_array.cast(pa.timestamp("us")))
            dt_array = ts_array._to_datetimearray()

            shifted = op(dt_array, other)
            check = shifted[~shifted.isna()] if shifted._hasna else shifted
            if not check.is_normalized:
                raise TypeError(
                    f"DateOffset {other} is intra-day and cannot be "
                    f"applied to date32/date64 arrays"
                )
            result_pa = pa.array(shifted._ndarray, from_pandas=True).cast(
                self._pa_array.type
            )
            return self._from_pyarrow_array(result_pa)

        result: Self | npt.NDArray[np.object_]
        if pa.types.is_string(self._pa_array.type) or pa.types.is_large_string(
            self._pa_array.type
        ):
            try:
                result = self._evaluate_op_method(other, op, ARROW_ARITHMETIC_FUNCS)
            except (pa.ArrowInvalid, pa.ArrowTypeError):
                result = self._str_arith_method_object_fallback(other, op)
        else:
            result = self._evaluate_op_method(other, op, ARROW_ARITHMETIC_FUNCS)

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Cast the array to timestamp[pyarrow] before applying time-aware offsets.
  2. Use only day-granular offsets with date types: pd.DateOffset(days=1).
  3. Convert to datetime64[ns] for full temporal arithmetic.
  4. Normalize the offset result or strip time after operating on timestamps.

Example fix

# before
shifted = date_arr + pd.DateOffset(hours=5)  # TypeError
# after
shifted = date_arr.astype('timestamp[us][pyarrow]') + pd.DateOffset(hours=5)
Defensive patterns

Strategy: type-guard

Validate before calling

import pyarrow as pa
from pandas.core.arrays.arrow import ArrowExtensionArray

def shift_dates(arr, offset):
    if isinstance(arr, ArrowExtensionArray):
        t = arr._pa_array.type
        if pa.types.is_date(t) and not getattr(offset, 'is_on_offset', lambda ts: True).__call__(None) if False else not _is_day_granular(offset):
            arr = arr.astype('timestamp[us][pyarrow]')
    return arr + offset

def _is_day_granular(offset):
    return getattr(offset, '_use_relativedelta', False) or offset.nanos == 0 and (offset.days != 0 or offset.delta == 0)

out = shift_dates(date_arr, pd.DateOffset(hours=5))

Type guard

import pyarrow as pa
from pandas.core.arrays.arrow import ArrowExtensionArray

def needs_timestamp_cast_for_offset(arr, offset) -> bool:
    if not isinstance(arr, ArrowExtensionArray):
        return False
    if not pa.types.is_date(arr._pa_array.type):
        return False
    # any sub-day component?
    return getattr(offset, 'nanos', 0) != 0 or getattr(offset, '_hours', 0) != 0 or getattr(offset, '_minutes', 0) != 0 or getattr(offset, '_seconds', 0) != 0

Try / catch

try:
    out = date_arr + offset
except TypeError as e:
    if 'intra-day' in str(e):
        out = date_arr.astype('timestamp[us][pyarrow]') + offset
    else:
        raise

Prevention

When it happens

Trigger: `date_arr + pd.DateOffset(hours=5)`, `date_arr + pd.Timedelta('1h')` style offsets, or `date_arr + pd.offsets.Hour()` on a date32[pyarrow]/date64[pyarrow] array. Any offset whose n != 0 for sub-day units (hour/minute/second) fails the normalization check.

Common situations: Storing dates (not timestamps) in pyarrow date types then adding time-aware offsets; mixing pandas DateOffset semantics with pyarrow date types; assuming DateOffset(days=1) is fine but accidentally passing a BusinessHour offset.

Related errors


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