{"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":382,"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":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L364-L400","documentation":"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.","triggerScenarios":"s.astype('timedelta64[m]'); s.astype('timedelta64[D]'); arr.astype(np.dtype('timedelta64[h]').","commonSituations":"Downstream code casts timedelta Series to coarser units expecting numpy parity; receiving a dtype string from config that includes an unsupported unit.","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."],"exampleFix":"// before\ns.astype('timedelta64[D]')  # ValueError\n// after\ns.astype('timedelta64[s]')\n# or for day-grained display\ns.dt.to_pytimedelta()","handlingStrategy":"validation","validationCode":"SUPPORTED = {'s','ms','us','ns'}\ndef safe_td_astype(s, unit):\n    if unit not in SUPPORTED:\n        raise ValueError(f\"Unsupported timedelta unit {unit!r}; use one of {SUPPORTED}\")\n    return s.astype(f'timedelta64[{unit}]')","typeGuard":"def is_supported_td64_dtype_str(dtype_str) -> bool:\n    import re\n    m = re.match(r'timedelta64\\[(.+)\\]', dtype_str)\n    return bool(m) and m.group(1) in {'s','ms','us','ns'}","tryCatchPattern":"try:\n    s.astype(dtype_str)\nexcept ValueError as e:\n    if 'Supported resolutions' in str(e):\n        s.as_unit('s')  # or pick an appropriate supported unit\n    else:\n        raise","preventionTips":["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."],"tags":["pandas","timedelta","astype","resolution","unit"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}