pandas-dev/pandas · error · ValueError
Values resolution does not match dtype.
Error message
Values resolution does not match dtype.
What it means
TimedeltaArray._validate_dtype raises ValueError when the requested dtype's resolution (e.g. timedelta64[s]) does not match the resolution of the supplied values array. The array's data and the dtype must agree on time unit to prevent silent rescaling.
Solutions
- Ensure the dtype passed matches values.dtype: pass dtype=values.dtype.
- Convert the values to the desired unit with astype_overflowsafe before constructing.
- Use the public pd.TimedeltaIndex / pd.to_timedelta constructors, which handle resolution matching.
Example fix
// before
arr = np.array([1,2,3], dtype='timedelta64[s]')
TimedeltaArray._simple_new(arr, dtype=np.dtype('timedelta64[ns]')) # ValueError
// after
TimedeltaArray._simple_new(arr, dtype=arr.dtype) Defensive patterns
Strategy: validation
Validate before calling
def build_td_array(values, dtype=None):
if dtype is None:
dtype = values.dtype
if dtype != values.dtype:
raise ValueError(f"dtype {dtype} != values.dtype {values.dtype}")
return dtype Type guard
def td_dtype_matches_values(values, dtype) -> bool:
return dtype == values.dtype Try / catch
try:
TimedeltaArray._simple_new(values, dtype=dtype)
except ValueError as e:
if 'resolution does not match' in str(e):
TimedeltaArray._simple_new(values, dtype=values.dtype)
else:
raise Prevention
- Pass dtype=values.dtype when constructing TimedeltaArray internals.
- Prefer pd.to_timedelta / pd.TimedeltaIndex over internal constructors.
- Use astype_overflowsafe to align resolutions before construction.
When it happens
Trigger: Internally constructing a TimedeltaArray with values of dtype timedelta64[ms] but passing dtype=timedelta64('ns'); calling _simple_new or _validate_dtype with mismatched unit parameters.
Common situations: Custom subclasses or internal callers passing a stale dtype; building a TimedeltaArray from raw int64 views with one unit while declaring another; misalignment after astype_overflowsafe failures.
Related errors
- Values resolution does not match dtype.
- Cannot convert from to . Supported resolutions are 's'…
- cumprod not supported for Timedelta.
- does not have a resolution.
- Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/43e71ff706d0b281.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/timedeltas.py:247
-------
numpy.dtype
"""
return self._ndarray.dtype
@property # NB: override with cache_readonly in immutable subclasses
def _resolution_obj(self) -> Resolution:
return get_resolution(self.asi8, tz=None, reso=self._creso)
# ----------------------------------------------------------------
# Constructors
@classmethod
def _validate_dtype(cls, values, dtype):
# used in TimeLikeOps.__init__
dtype = _validate_td64_dtype(dtype)
_validate_td64_dtype(values.dtype)
if dtype != values.dtype:
raise ValueError("Values resolution does not match dtype.")
return dtype
# error: Signature of "_simple_new" incompatible with supertype "NDArrayBacked"
@classmethod
def _simple_new( # type: ignore[override]
cls,
values: npt.NDArray[np.timedelta64],
dtype: np.dtype[np.timedelta64] = TD64NS_DTYPE,
) -> Self:
# Require td64 dtype, not unit-less, matching values.dtype
assert lib.is_np_dtype(dtype, "m")
assert not tslibs.is_unitless(dtype)
assert isinstance(values, np.ndarray), type(values)
assert dtype == values.dtype
return super()._simple_new(values=values, dtype=dtype)
@classmethodView on GitHub (pinned to 3b7651241d)