pandas-dev/pandas · error · ValueError
Passing in 'timedelta' dtype with no precision is not allowe
Error message
Passing in 'timedelta' dtype with no precision is not allowed. Please pass in 'timedelta64[ns]' instead.
What it means
Raised by _validate_td64_dtype when dtype equals numpy 'm8' (timedelta64 with no resolution). Pandas refuses bare 'timedelta' because nanosecond resolution is the only representation it stores; you must specify timedelta64[ns]. GH#24806.
Source
Thrown at pandas/core/arrays/timedeltas.py:1413
errors to be ignored; they are caught and subsequently ignored at a
higher level.
"""
# coerce Index to np.ndarray, converting string-dtype if necessary
values = np.asarray(data, dtype=np.object_)
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
- Specify the resolution explicitly: 'timedelta64[ns]'.
- If accepting user dtype strings, validate/normalize before passing to pandas.
- Use pd.to_timedelta() to infer dtype rather than passing a bare dtype.
Example fix
// before
s = df['x'].astype('timedelta')
// after
s = df['x'].astype('timedelta64[ns]') Defensive patterns
Strategy: validation
Validate before calling
if str(dtype) == 'timedelta':
dtype = 'timedelta64[ns]' Type guard
def has_td_resolution(dtype_str) -> bool:
return dtype_str not in ('timedelta', 'm8', 'timedelta64') Try / catch
try:
s = df['x'].astype(dtype)
except ValueError as e:
if 'no precision' in str(e):
s = df['x'].astype('timedelta64[ns]')
else:
raise Prevention
- Always specify [ns] for timedelta dtypes.
- Normalize user dtype strings.
- Use to_timedelta() to avoid manual dtype strings.
When it happens
Trigger: `pd.TimedeltaIndex(..., dtype='timedelta')`, `.astype('timedelta')`, or `pd.Series(..., dtype='timedelta')`. Anywhere a unit-less timedelta dtype string is supplied.
Common situations: Copy-pasted dtype strings; tutorials using older numpy syntax; user input not validated against supported resolutions.
Related errors
- dtype '{dtype}' is invalid, should be np.timedelta64 dtype
- Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'
- Column {colname} must have a numeric dtype. Found '{dtype}'
- codes need to be array-like integers
- {dtype=} does not have a resolution.
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/645da3b018f50624.
Report an issue: GitHub.