{"record":{"id":"645da3b018f50624","repo":"pandas-dev/pandas","slug":"passing-in-timedelta-dtype-with-no-precision-is","errorCode":null,"errorMessage":"Passing in 'timedelta' dtype with no precision is not allowed. Please pass in 'timedelta64[ns]' instead.","messagePattern":"Passing in 'timedelta' dtype with no precision is not allowed\\. Please pass in 'timedelta64\\[ns\\]' instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":1433,"sourceCode":"    errors to be ignored; they are caught and subsequently ignored at a\n    higher level.\n    \"\"\"\n    # coerce Index to np.ndarray, converting string-dtype if necessary\n    values = np.asarray(data, dtype=np.object_)\n\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":1415,"sourceCodeEnd":1441,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L1415-L1441","documentation":"Raised by _validate_td64_dtype when the supplied dtype is the unit-less `timedelta64` (numpy dtype 'm8', no precision). Pandas requires an explicit resolution (GH#24806); a bare timedelta dtype is ambiguous because the backing nanosecond representation needs a defined unit. The message directs the caller to use 'timedelta64[ns]'.","triggerScenarios":"Constructing a TimedeltaIndex/Index with dtype='timedelta' or dtype='timedelta64' (no unit), e.g. `pd.Index([], dtype='timedelta')`.","commonSituations":"Copying a loose dtype string from documentation or older code; building dtype dynamically without appending a unit.","solutions":["Specify a resolution: use 'timedelta64[ns]' (or 's','ms','us' as supported).","Omit the dtype entirely and let pandas infer it from timedelta data.","Validate dtype strings before passing them to constructors."],"exampleFix":"# before\npd.Index(pd.to_timedelta([1, 2], unit='D'), dtype='timedelta')  # ValueError\n\n# after\npd.Index(pd.to_timedelta([1, 2], unit='D'), dtype='timedelta64[ns]')","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef validate_td_dtype_str(dtype_str: str) -> bool:\n    try:\n        dt = np.dtype(dtype_str)\n    except TypeError:\n        return False\n    return dt != np.dtype('m8') and dt.kind == 'm'","typeGuard":"null","tryCatchPattern":"try:\n    idx = pd.TimedeltaIndex(data, dtype=dtype)\nexcept ValueError as e:\n    if 'no precision' in str(e):\n        idx = pd.TimedeltaIndex(data, dtype='timedelta64[ns]')\n    else:\n        raise","preventionTips":["Always specify a resolution (e.g. 'timedelta64[ns]').","Omit dtype and let pandas infer from timedelta data when unsure."],"tags":["timedelta","dtype","validation","valueerror","units"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}