pandas-dev/pandas · error · ValueError

Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'

Error message

Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'

What it means

Raised by _validate_td64_dtype for a timedelta64 dtype whose resolution is not one of the supported set ('s','ms','us','ns'). Pandas only stores nanoseconds internally and only those four inbound resolutions are accepted for casting.

Source

Thrown at pandas/core/arrays/timedeltas.py:1418

    result = array_to_timedelta64(values, unit=unit, errors=errors)
    return result


def _validate_td64_dtype(dtype) -> DtypeObj:
    dtype = pandas_dtype(dtype)
    if dtype == np.dtype("m8"):
        # no precision disallowed GH#24806
        msg = (
            "Passing in 'timedelta' dtype with no precision is not allowed. "
            "Please pass in 'timedelta64[ns]' instead."
        )
        raise ValueError(msg)

    if not lib.is_np_dtype(dtype, "m"):
        raise ValueError(f"dtype '{dtype}' is invalid, should be np.timedelta64 dtype")
    elif not is_supported_dtype(dtype):
        raise ValueError("Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'")

    return dtype

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Use one of the supported resolutions: 's', 'ms', 'us', or 'ns'.
  2. Drop the unit and let pandas default to ns.
  3. For durations in days/hours, store as ns and format on output.

Example fix

// before
s = df['x'].astype('timedelta64[h]')

// after
s = df['x'].astype('timedelta64[ns]')
Defensive patterns

Strategy: validation

Validate before calling

supported = {'s','ms','us','ns'}
unit = str(dtype).strip('timedelta64[] ')
if unit not in supported:
    raise ValueError(f'unsupported timedelta resolution: {unit}')

Type guard

def is_supported_td_resolution(dtype) -> bool:
    import re
    m = re.search(r'timedelta64\[([a-z]+)\]', str(dtype))
    return bool(m and m.group(1) in {'s','ms','us','ns'})

Try / catch

try:
    s = df['x'].astype(dtype)
except ValueError as e:
    if 'Supported timedelta64 resolutions' in str(e):
        s = df['x'].astype('timedelta64[ns]')
    else:
        raise

Prevention

When it happens

Trigger: `pd.TimedeltaIndex(..., dtype='timedelta64[h]')`, `.astype('timedelta64[D]')`, or any of 'h','D','M','Y','W','fs','as','ps'.

Common situations: Using numpy's broader unit vocabulary; reading dtype strings from configs that allow wider units; legacy code targeting older pandas.

Related errors


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