pandas-dev/pandas · error · ValueError
Cannot convert from to . Supported resolutions are 's'…
Error message
Cannot convert from {self.dtype} to {dtype}. Supported resolutions are 's', 'ms', 'us', 'ns' What it means
TimedeltaArray.astype refuses conversion to a numpy timedelta64 dtype whose unit is outside the supported resolution set {s, ms, us, ns}. Other resolutions (m, h, D, etc.) cannot be represented without overflow ambiguity, so pandas raises rather than silently coerce.
Solutions
- Cast to one of the supported units: s.astype('timedelta64[s]').
- For coarser display, use .as_unit('s') or format the output instead.
- Convert via int64 nanoseconds and reapply a unit only if necessary.
Example fix
// before
s.astype('timedelta64[D]') # ValueError
// after
s.astype('timedelta64[s]')
# or for day-grained display
s.dt.to_pytimedelta() Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'s','ms','us','ns'}
def safe_td_astype(s, unit):
if unit not in SUPPORTED:
raise ValueError(f"Unsupported timedelta unit {unit!r}; use one of {SUPPORTED}")
return s.astype(f'timedelta64[{unit}]') Type guard
def is_supported_td64_dtype_str(dtype_str) -> bool:
import re
m = re.match(r'timedelta64\[(.+)\]', dtype_str)
return bool(m) and m.group(1) in {'s','ms','us','ns'} Try / catch
try:
s.astype(dtype_str)
except ValueError as e:
if 'Supported resolutions' in str(e):
s.as_unit('s') # or pick an appropriate supported unit
else:
raise Prevention
- Restrict astype targets to timedelta64[s/ms/us/ns].
- Use .as_unit or .dt for display in other units.
- Validate dtype strings from configuration before casting.
When it happens
Trigger: s.astype('timedelta64[m]'); s.astype('timedelta64[D]'); arr.astype(np.dtype('timedelta64[h]').
Common situations: Downstream code casts timedelta Series to coarser units expecting numpy parity; receiving a dtype string from config that includes an unsupported unit.
Related errors
- 'unit' must be one of 's', 'ms', 'us', 'ns'
- Supported units are 's', 'ms', 'us', 'ns'
- 'unit' must be one of 's', 'ms', 'us', 'ns'
- Values resolution does not match dtype.
- Cannot add or subtract timedelta64[ns] dtype from
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/9a3460a541ab2b45.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/timedeltas.py:382
def astype(self, dtype, copy: bool = True):
# We handle
# --> timedelta64[ns]
# --> timedelta64
# DatetimeLikeArrayMixin super call handles other cases
dtype = pandas_dtype(dtype)
if lib.is_np_dtype(dtype, "m"):
if dtype == self.dtype:
if copy:
return self.copy()
return self
if is_supported_dtype(dtype):
# unit conversion e.g. timedelta64[s]
res_values = astype_overflowsafe(self._ndarray, dtype, copy=False)
return type(self)._simple_new(res_values, dtype=res_values.dtype)
else:
raise ValueError(
f"Cannot convert from {self.dtype} to {dtype}. "
"Supported resolutions are 's', 'ms', 'us', 'ns'"
)
return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy=copy)
def _iter_convert_chunk(self, data: np.ndarray) -> np.ndarray:
return ints_to_pytimedelta(data, box=True)
# ----------------------------------------------------------------
# Reductions
def sum(
self,
*,
axis: AxisInt | None = None,
dtype: NpDtype | None = None,
out=None,View on GitHub (pinned to 3b7651241d)