pandas-dev/pandas · error · ValueError

{dtype=} does not have a resolution.

Error message

{dtype=} does not have a resolution.

What it means

Raised by dtype_to_unit when an ArrowDtype is passed whose kind is not datetime ('M') or timedelta ('m'). The function exists to extract a time resolution string; only temporal Arrow dtypes carry one, so any other Arrow type (int, string, bool) is rejected.

Source

Thrown at pandas/core/arrays/datetimelike.py:2530

def dtype_to_unit(dtype: DatetimeTZDtype | np.dtype | ArrowDtype) -> str:
    """
    Return the unit str corresponding to the dtype's resolution.

    Parameters
    ----------
    dtype : DatetimeTZDtype or np.dtype
        If np.dtype, we assume it is a datetime64 dtype.

    Returns
    -------
    str
    """
    if isinstance(dtype, DatetimeTZDtype):
        return dtype.unit
    elif isinstance(dtype, ArrowDtype):
        if dtype.kind not in "mM":
            raise ValueError(f"{dtype=} does not have a resolution.")
        return dtype.pyarrow_dtype.unit
    return np.datetime_data(dtype)[0]

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Guard the call with dtype.kind in 'mM' before invoking dtype_to_unit.
  2. Ensure the ArrowDtype is temporal: pd.ArrowDtype(pa.timestamp('ns')) or pa.duration('ns').
  3. Branch on dtype before dispatching to temporal-specific helpers.

Example fix

# before
dtype_to_unit(pd.ArrowDtype(pa.int64()))

# after
if dtype.kind in 'mM':
    unit = dtype_to_unit(dtype)
else:
    raise TypeError(f'{dtype} is not temporal')
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(dtype, pd.ArrowDtype) and dtype.kind not in 'mM':
    raise TypeError(f'{dtype} is not temporal; cannot resolve a unit')

Type guard

def is_temporal_arrow(dtype) -> bool:
    return isinstance(dtype, pd.ArrowDtype) and dtype.kind in 'mM'

Try / catch

try:
    dtype_to_unit(dtype)
except ValueError as e:
    if 'does not have a resolution' in str(e):
        # not temporal; pick a default unit or skip
        unit = 'ns'
    else: raise

Prevention

When it happens

Trigger: Internally calling dtype_to_unit on a non-temporal pandas ArrowDtype (e.g. pd.ArrowDtype(pa.int64()), pd.ArrowDtype(pa.string())). Reachable when code generic over dtypes routes an Arrow column through the temporal conversion path.

Common situations: Generic type-coercion helpers that assume every Arrow dtype is temporal; mislabeling a column dtype; mixing Arrow-backed numeric columns into a datetime cast pipeline.

Related errors


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