{"record":{"id":"9a3460a541ab2b45","repo":"pandas-dev/pandas","slug":"cannot-convert-from-self-dtype-to-dtype-suppo","errorCode":null,"errorMessage":"Cannot convert from {self.dtype} to {dtype}. Supported resolutions are 's', 'ms', 'us', 'ns'","messagePattern":"Cannot convert from (.+?) to (.+?)\\. Supported resolutions are 's', 'ms', 'us', 'ns'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":365,"sourceCode":"    def astype(self, dtype, copy: bool = True):\n        # We handle\n        #   --> timedelta64[ns]\n        #   --> timedelta64\n        # DatetimeLikeArrayMixin super call handles other cases\n        dtype = pandas_dtype(dtype)\n\n        if lib.is_np_dtype(dtype, \"m\"):\n            if dtype == self.dtype:\n                if copy:\n                    return self.copy()\n                return self\n\n            if is_supported_dtype(dtype):\n                # unit conversion e.g. timedelta64[s]\n                res_values = astype_overflowsafe(self._ndarray, dtype, copy=False)\n                return type(self)._simple_new(res_values, dtype=res_values.dtype)\n            else:\n                raise ValueError(\n                    f\"Cannot convert from {self.dtype} to {dtype}. \"\n                    \"Supported resolutions are 's', 'ms', 'us', 'ns'\"\n                )\n\n        return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy=copy)\n\n    def _iter_convert_chunk(self, data: np.ndarray) -> np.ndarray:\n        return ints_to_pytimedelta(data, box=True)\n\n    # ----------------------------------------------------------------\n    # Reductions\n\n    def sum(\n        self,\n        *,\n        axis: AxisInt | None = None,\n        dtype: NpDtype | None = None,\n        out=None,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/timedeltas.py#L347-L383","documentation":"Raised by TimedeltaArray.astype when the target timedelta64 dtype is not in the supported resolution set (s/ms/us/ns). pandas only supports those four resolutions for timedelta64 because the conversion is overflow-safe; finer (e.g. timedelta64[ps],[fs],[as]) or unusual units cannot be represented without silent overflow, so a ValueError is raised naming the current and target dtypes.","triggerScenarios":"Calling `td_arr.astype('timedelta64[ms]')` works, but `td_arr.astype('timedelta64[D]')`, `astype('timedelta64[h]')`, or `astype('timedelta64[ps]')` raises because those are not in is_supported_dtype. The else-branch at timedeltas.py:365 fires.","commonSituations":"Interop with systems expecting day/hour-resolution arrays; copying dtype strings from numpy docs that list units pandas does not support; converting large-nanosecond values to coarser-than-supported units.","solutions":["Cast to a supported resolution first: `td_arr.astype('timedelta64[s]')`, then handle further unit conversion in Python if needed.","For day/hour granularity, compute via `.dt.days` / `.dt.components` rather than astype.","If you need a non-supported numpy unit, go through int64: `td_arr.asi8.astype(...)` with explicit unit math."],"exampleFix":"# before\narr.astype('timedelta64[D]')  # ValueError\n# after\narr.astype('timedelta64[s]')  # then .dt.days for day values","handlingStrategy":"validation","validationCode":"SUPPORTED = {'s','ms','us','ns'}\n\ndef safe_td_astype(arr, target):\n    import re\n    m = re.match(r'timedelta64\\[(\\w+)\\]', target)\n    if m and m.group(1) not in SUPPORTED:\n        raise ValueError(f'{target} unsupported; use one of {SUPPORTED}')\n    return arr.astype(target)","typeGuard":"import re\nSUPPORTED = {'s','ms','us','ns'}\ndef is_supported_td_dtype(dtype_str) -> bool:\n    m = re.match(r'timedelta64\\[(\\w+)\\]', dtype_str)\n    return bool(m) and m.group(1) in SUPPORTED","tryCatchPattern":"try:\n    return arr.astype(target)\nexcept ValueError as e:\n    if 'Cannot convert from' in str(e) and 'Supported resolutions' in str(e):\n        return arr.astype('timedelta64[s]')\n    raise","preventionTips":["Restrict target units to s/ms/us/ns at API boundaries.","Use .dt.days/.dt.components for day/hour granularity instead of astype.","Document supported resolutions alongside your dtype options."],"tags":["timedelta","astype","resolution","valueerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}