{"record":{"id":"753eecf578dc53a9","repo":"pandas-dev/pandas","slug":"err-args","errorCode":null,"errorMessage":"{err.args}","messagePattern":"\\{err\\.args\\}","errorType":"exception","errorClass":"OutOfBoundsTimedelta","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":1294,"sourceCode":"            # check pass incorrectly for OOB values like float(2**63).\n            # Exclude values outside the int64 domain from the check.\n            i64 = np.iinfo(np.int64)\n            in_int64_range = (data >= np.float64(i64.min)) & (\n                data < np.float64(i64.max)\n            )\n            all_round = (mask | (in_int64_range & (data == int_data))).all()\n            if all_round:\n                result = sequence_to_td64ns(\n                    int_data, copy=False, unit=unit, errors=errors\n                )\n                result[mask] = iNaT\n                return result\n\n        data = data.astype(np.float64, copy=False)\n        try:\n            data = cast_from_unit_vectorized(data, unit or \"ns\")\n        except OutOfBoundsDatetime as err:\n            raise OutOfBoundsTimedelta(*err.args) from err\n        data[mask] = iNaT\n        data = data.view(\"m8[ns]\")\n        copy = False\n\n    elif lib.is_np_dtype(data.dtype, \"m\"):\n        if not is_supported_dtype(data.dtype):\n            # cast to closest supported unit, i.e. s or ns\n            new_dtype = get_supported_dtype(data.dtype)\n            data = astype_overflowsafe(data, dtype=new_dtype, copy=False)\n            copy = False\n\n    else:\n        # This includes datetime64-dtype, see GH#23539, GH#29794\n        raise TypeError(f\"dtype {data.dtype} cannot be converted to timedelta64[ns]\")\n\n    if not copy:\n        data = np.asarray(data)\n    else:","sourceCodeStart":1276,"sourceCodeEnd":1312,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/timedeltas.py#L1276-L1312","documentation":"Re-raise site inside sequence_to_td64ns: when converting float data through cast_from_unit_vectorized raises OutOfBoundsDatetime (values out of int64 range after unit scaling), pandas re-raises it as OutOfBoundsTimedelta, preserving the original message via err.args. This is a conversion-overflow guard for to_timedelta on floats with a unit.","triggerScenarios":"Calling pd.to_timedelta on float values with a unit that pushes them out of int64-nanosecond range, e.g. `pd.to_timedelta([1e20], unit='s')`. NaT-handling branch sets mask but the unmasked conversion overflows.","commonSituations":"Loading telemetry with huge epoch offsets; specifying a coarse unit ('D','W') on already-large floats; unit-mismatch bugs.","solutions":["Reduce magnitude: clip or scale the floats before conversion.","Use a coarser target by converting in steps (e.g. seconds first, then to_timedelta).","Pass errors='coerce' to surface NaT instead of raising."],"exampleFix":"// before\ns = pd.to_timedelta([1e20], unit='s')\n\n// after\ns = pd.to_timedelta([1e20], unit='s', errors='coerce')","handlingStrategy":"try-catch","validationCode":"import numpy as np\narr = np.asarray(data, dtype='float64')\nprojected = arr * {'s': 10**9, 'ms': 10**6, 'us': 10**3, 'ns': 1}.get(unit, 1)\nif np.nanmax(np.abs(projected)) >= 2.0**63:\n    raise ValueError('float values overflow timedelta64[ns] after unit scaling')","typeGuard":null,"tryCatchPattern":"try:\n    s = pd.to_timedelta(data, unit=unit)\nexcept OutOfBoundsTimedelta:\n    s = pd.to_timedelta(data, unit=unit, errors='coerce')","preventionTips":["Bound float magnitudes before to_timedelta.","Use errors='coerce' on untrusted input.","Validate unit conversions offline."],"tags":["timedelta","overflow","conversion","to-timedelta"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}