{"record":{"id":"1995e78bdfa5d787","repo":"pandas-dev/pandas","slug":"at-least-start-or-end-should-be-specified-if-a","errorCode":null,"errorMessage":"at least 'start' or 'end' should be specified if a 'period' is given.","messagePattern":"at least 'start' or 'end' should be specified if a 'period' is given\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/_ranges.py","lineNumber":92,"sourceCode":"        raise ValueError(\n            f\"freq={freq} is incompatible with unit={unit}. \"\n            \"Use a lower freq or a higher unit instead.\"\n        ) from err\n    stride = int(td._value)\n\n    if periods is None and istart is not None and iend is not None:\n        b = istart\n        # cannot just use e = Timestamp(end) + 1 because arange breaks when\n        # stride is too large, see GH10887\n        e = b + (iend - b) // stride * stride + stride // 2 + 1\n    elif istart is not None and periods is not None:\n        b = istart\n        e = _generate_range_overflow_safe(b, periods, stride, side=\"start\")\n    elif iend is not None and periods is not None:\n        e = iend + stride\n        b = _generate_range_overflow_safe(e, periods, stride, side=\"end\")\n    else:\n        raise ValueError(\n            \"at least 'start' or 'end' should be specified if a 'period' is given.\"\n        )\n\n    return range_to_ndarray(range(b, e, stride))\n\n\ndef generate_daily_offset_range(\n    start: Timestamp | None,\n    end: Timestamp | None,\n    periods: int | None,\n    freq: BaseOffset,\n    unit: TimeUnit = \"ns\",\n) -> npt.NDArray[np.int64]:\n    \"\"\"\n    Generate a range for offsets whose on-offset dates are a subset of a\n    daily grid, by generating a daily range and filtering.\n\n    This is a performance optimization (GH#16463) for offsets like BusinessDay","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/_ranges.py#L74-L110","documentation":"`ValueError(\"at least 'start' or 'end' should be specified if a 'period' is given.\")` from `generate_regular_range`'s final `else` branch. It fires when none of the supported parameter combinations are met: (periods None + start + end), (start + periods), or (end + periods). In practice the message points at the most common cause — `periods` given without either `start` or `end` — though the branch also catches 'periods=None but only one of start/end' and 'all None'.","triggerScenarios":"Calling `pd.date_range(periods=N)` without `start` or `end`; calling `pd.date_range(start=..., periods=None, end=None)` (only start); calling `pd.date_range()` with none of the three. The error surfaces from the regular-range generator used by `date_range` for fixed-frequency offsets.","commonSituations":"Variable confusion (passing `periods` as positional but it lands in a different slot); building ranges programmatically where `start` and `end` are both None at runtime; refactoring that dropped a required argument.","solutions":["Provide `start` together with `periods`, or `end` together with `periods`, or both `start` and `end`.","If `periods` is None, supply both `start` and `end`.","Add an upstream assert: `assert start is not None or end is not None` before calling `date_range`."],"exampleFix":"// before\npd.date_range(periods=5, freq='D')   # no start/end -> ValueError\n\n// after\npd.date_range(start='2020-01-01', periods=5, freq='D')","handlingStrategy":"validation","validationCode":"if start is None and end is None:\n    raise ValueError('date_range needs start or end (or both with periods=None)')\npd.date_range(start=start, end=end, periods=periods, freq=freq)","typeGuard":"def has_range_inputs(start, end, periods) -> bool:\n    return (start is not None and periods is not None) or (end is not None and periods is not None) or (start is not None and end is not None)","tryCatchPattern":"try:\n    rng = pd.date_range(start=start, periods=periods, freq=freq)\nexcept ValueError as e:\n    if \"at least 'start' or 'end'\" in str(e):\n        raise ValueError('Pass start= or end= alongside periods=') from e\n    raise","preventionTips":["Always pass start (or end) when using periods","Use keyword arguments to avoid positional mix-ups"],"tags":["date-range","argument-validation","freq"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}