{"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":"validation","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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimes.py#L404-L440","documentation":"Raised by DatetimeArray._generate_range after coercing start/end to Timestamp when either is pd.NaT. Generating a range from a not-a-time boundary is impossible (the step math has no anchor), so it is rejected before unit/freq resolution proceeds.","triggerScenarios":"pd.date_range(start=pd.NaT, periods=5, freq='D'); pd.date_range(end=pd.NaT, ...); passing a column value that parsed to NaT (e.g. empty string, unparseable date) as start or end.","commonSituations":"Reading start/end from user input or config that may be blank; selecting index[0] from an index that contains NaT; chaining date_range to upstream parsing that can yield NaT.","solutions":["Validate start/end before the call: if pd.isna(start) or pd.isna(end): handle missing-boundary case.","Clean or filter NaT from the source column before passing its first/last value.","Use try/except around the parse to substitute a default Timestamp when input is missing."],"exampleFix":"// before\nstart = pd.to_datetime('')  # NaT\npd.date_range(start, periods=5, freq='D')  # ValueError: Neither start nor end can be NaT\n\n// after\nstart = pd.to_datetime(user_input) if user_input else pd.Timestamp('2020-01-01')\npd.date_range(start, periods=5, freq='D')","handlingStrategy":"validation","validationCode":"def safe_range_bound(bound):\n    ts = pd.Timestamp(bound)\n    if pd.isna(ts):\n        raise ValueError(f\"boundary {bound!r} parsed to NaT\")\n    return ts","typeGuard":"def is_valid_range_bound(bound) -> bool:\n    return not pd.isna(pd.Timestamp(bound)) if bound is not None else False","tryCatchPattern":"try:\n    rng = pd.date_range(start=start, periods=5, freq=\"D\")\nexcept ValueError as e:\n    if \"can be NaT\" in str(e):\n        start = pd.Timestamp.today().normalize()\n        rng = pd.date_range(start=start, periods=5, freq=\"D\")\n    else:\n        raise","preventionTips":["Validate pd.isna on start/end before calling date_range.","Filter NaT from source columns before taking their first/last value.","Default missing bounds to a sensible Timestamp, not None-through-NaT."],"tags":["pandas","date-range","nat","validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}