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 when the dtype is a valid numpy timedelta64 dtype but its resolution is not one pandas supports. Only 's' (seconds), 'ms', 'us', and 'ns' are supported because the nanosecond-backed representation can losslessly represent those; coarser (m, h, D) or finer (fs, as, ps) resolutions are rejected.

Solutions

  1. Use one of the supported resolutions: 's', 'ms', 'us', or 'ns'.
  2. If you need to express minutes/hours/days, construct from data with the correct numeric magnitude and unit, letting pandas store it as ns.
  3. Build the dtype dynamically from the allowed set.

Example fix

# before
pd.TimedeltaIndex([], dtype='timedelta64[m]')  # ValueError

# after
pd.TimedeltaIndex([1, 2, 3], unit='m', dtype='timedelta64[ns]')
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_TD_UNITS = {'s', 'ms', 'us', 'ns'}

def is_supported_td_resolution(dtype_str: str) -> bool:
    # expects form timedelta64[<unit>]
    if '[' in dtype_str:
        unit = dtype_str[dtype_str.index('[') + 1:dtype_str.index(']')]
        return unit in SUPPORTED_TD_UNITS
    return False

Type guard

null

Try / catch

try:
    idx = pd.TimedeltaIndex([], dtype=dtype)
except ValueError as e:
    if 'Supported timedelta64 resolutions' in str(e):
        idx = pd.TimedeltaIndex([], dtype='timedelta64[ns]')
    else:
        raise

Prevention

When it happens

Trigger: `pd.TimedeltaIndex([], dtype='timedelta64[m]')`, or any resolution outside {s, ms, us, ns}.

Common situations: Selecting minute/hour/day timedelta resolutions expecting direct support; numpy dtype strings carrying unsupported precisions.

Related errors


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

Appendix: source

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

    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 3b7651241d)