{"record":{"id":"2e92b94278d7c12f","repo":"pandas-dev/pandas","slug":"supported-timedelta64-resolutions-are-s-ms","errorCode":null,"errorMessage":"Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'","messagePattern":"Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":1438,"sourceCode":"\n    result = array_to_timedelta64(values, unit=unit, errors=errors)\n    return result\n\n\ndef _validate_td64_dtype(dtype) -> DtypeObj:\n    dtype = pandas_dtype(dtype)\n    if dtype == np.dtype(\"m8\"):\n        # no precision disallowed GH#24806\n        msg = (\n            \"Passing in 'timedelta' dtype with no precision is not allowed. \"\n            \"Please pass in 'timedelta64[ns]' instead.\"\n        )\n        raise ValueError(msg)\n\n    if not lib.is_np_dtype(dtype, \"m\"):\n        raise ValueError(f\"dtype '{dtype}' is invalid, should be np.timedelta64 dtype\")\n    elif not is_supported_dtype(dtype):\n        raise ValueError(\"Supported timedelta64 resolutions are 's', 'ms', 'us', 'ns'\")\n\n    return dtype\n","sourceCodeStart":1420,"sourceCodeEnd":1441,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L1420-L1441","documentation":"Raised by _validate_td64_dtype when the dtype is a valid numpy timedelta64 dtype but its resolution is not one pandas supports. Only 's' (seconds), 'ms', 'us', and 'ns' are supported because the nanosecond-backed representation can losslessly represent those; coarser (m, h, D) or finer (fs, as, ps) resolutions are rejected.","triggerScenarios":"`pd.TimedeltaIndex([], dtype='timedelta64[m]')`, or any resolution outside {s, ms, us, ns}.","commonSituations":"Selecting minute/hour/day timedelta resolutions expecting direct support; numpy dtype strings carrying unsupported precisions.","solutions":["Use one of the supported resolutions: 's', 'ms', 'us', or 'ns'.","If you need to express minutes/hours/days, construct from data with the correct numeric magnitude and unit, letting pandas store it as ns.","Build the dtype dynamically from the allowed set."],"exampleFix":"# before\npd.TimedeltaIndex([], dtype='timedelta64[m]')  # ValueError\n\n# after\npd.TimedeltaIndex([1, 2, 3], unit='m', dtype='timedelta64[ns]')","handlingStrategy":"validation","validationCode":"SUPPORTED_TD_UNITS = {'s', 'ms', 'us', 'ns'}\n\ndef is_supported_td_resolution(dtype_str: str) -> bool:\n    # expects form timedelta64[<unit>]\n    if '[' in dtype_str:\n        unit = dtype_str[dtype_str.index('[') + 1:dtype_str.index(']')]\n        return unit in SUPPORTED_TD_UNITS\n    return False","typeGuard":"null","tryCatchPattern":"try:\n    idx = pd.TimedeltaIndex([], dtype=dtype)\nexcept ValueError as e:\n    if 'Supported timedelta64 resolutions' in str(e):\n        idx = pd.TimedeltaIndex([], dtype='timedelta64[ns]')\n    else:\n        raise","preventionTips":["Restrict timedelta resolutions to {s, ms, us, ns}.","Express minutes/hours/days via numeric data + unit, stored as ns."],"tags":["timedelta","dtype","resolution","validation","valueerror"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}