{"record":{"id":"d009742cfc2edad8","repo":"pandas-dev/pandas","slug":"neither-start-nor-end-can-be-nat","errorCode":null,"errorMessage":"Neither `start` nor `end` can be NaT","messagePattern":"Neither `start` nor `end` can be NaT","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":422,"sourceCode":"        periods = dtl.validate_periods(periods)\n        if freq is None and any(x is None for x in [periods, start, end]):\n            raise ValueError(\"Must provide freq argument if no data is supplied\")\n\n        if com.count_not_none(start, end, periods, freq) != 3:\n            raise ValueError(\n                \"Of the four parameters: start, end, periods, \"\n                \"and freq, exactly three must be specified\"\n            )\n        freq = to_offset(freq)\n\n        if start is not None:\n            start = Timestamp(start)\n\n        if end is not None:\n            end = Timestamp(end)\n\n        if start is NaT or end is NaT:\n            raise ValueError(\"Neither `start` nor `end` can be NaT\")\n\n        if unit is not None:\n            if unit not in [\"s\", \"ms\", \"us\", \"ns\"]:\n                raise ValueError(\"'unit' must be one of 's', 'ms', 'us', 'ns'\")\n        else:\n            unit = \"ns\"\n\n        if start is not None:\n            start = start.as_unit(unit, round_ok=False)\n        if end is not None:\n            end = end.as_unit(unit, round_ok=False)\n\n        left_inclusive, right_inclusive = validate_inclusive(inclusive)\n        start, end = _maybe_normalize_endpoints(start, end, normalize)\n        tz = _infer_tz_from_endpoints(start, end, tz)\n\n        if tz is not None:\n            # Localize the start and end arguments","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L404-L440","documentation":"Raised in _generate_range after Timestamp coercion when either start or end is pandas.NaT. Generating a range anchored on NaT is meaningless — there is no real reference instant — so it is rejected up front, before the freq/periods arithmetic would propagate the NaT silently.","triggerScenarios":"pd.date_range(start=pd.NaT, end='2020-01-05', periods=3); pd.date_range(start='2020-01-01', end=pd.NaT, freq='D'); passing a column value that is NaT as the start/end (e.g. df['start'].iloc[0] when the column is all-NaT).","commonSituations":"Start/end sourced from a row that is missing; upstream parsing returned NaT for an unparseable date string; timezone localization of an ambiguous/nonexistent time yielded NaT.","solutions":["Filter or fill NaT before using it as a bound: start = df['start'].dropna().iloc[0].","Validate with pd.isna(start) / pd.isna(end) and branch.","If the column may be empty, default to a real Timestamp or skip the range generation."],"exampleFix":"# before\nstart = pd.to_datetime(maybe_bad_string)  # may be NaT\npd.date_range(start, '2020-12-31', freq='D')\n\n# after\nstart = pd.to_datetime(maybe_bad_string)\nif pd.isna(start):\n    raise ValueError(f'unparseable start: {maybe_bad_string!r}')\npd.date_range(start, '2020-12-31', freq='D')","handlingStrategy":"validation","validationCode":"if pd.isna(start) or pd.isna(end):\n    raise ValueError('start/end cannot be NaT; supply a valid Timestamp')","typeGuard":"def is_valid_bound(x) -> bool:\n    return x is None or (isinstance(x, (pd.Timestamp, str)) and not pd.isna(pd.Timestamp(x)))","tryCatchPattern":"try:\n    pd.date_range(start, end, freq='D')\nexcept ValueError as e:\n    if 'can be NaT' in str(e):\n        start = df['start'].dropna().iloc[0]\n        pd.date_range(start, end, freq='D')\n    else: raise","preventionTips":["dropna() the source column before taking the bound.","Validate parsed timestamps with pd.isna before use."],"tags":["date-range","nat","constructor","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}