{"record":{"id":"0a68bb2741d2d115","repo":"pandas-dev/pandas","slug":"must-provide-freq-argument-if-no-data-is-supplied","errorCode":null,"errorMessage":"Must provide freq argument if no data is supplied","messagePattern":"Must provide freq argument if no data is supplied","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":406,"sourceCode":"\n    @classmethod\n    def _generate_range(\n        cls,\n        start,\n        end,\n        periods: int | None,\n        freq,\n        tz=None,\n        normalize: bool = False,\n        ambiguous: TimeAmbiguous = \"raise\",\n        nonexistent: TimeNonexistent = \"raise\",\n        inclusive: IntervalClosedType = \"both\",\n        *,\n        unit: TimeUnit = \"ns\",\n    ) -> Self:\n        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:","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimes.py#L388-L424","documentation":"Raised by DatetimeArray._generate_range when freq is None and at least one of periods/start/end is also None. With no frequency and no full (start,end,periods) triple, the range cannot be generated; this fires before the 'exactly three' check to give the most actionable message.","triggerScenarios":"pd.date_range() with no arguments; pd.date_range(start='2020-01-01') without freq or periods; pd.date_range(periods=5) with nothing else; any call where freq is missing and the triple is incomplete.","commonSituations":"Calling date_range inside a helper that conditionally omits freq; passing None through from a config dict; defaulting arguments to None and forgetting the fallback.","solutions":["Provide freq='D' (or another offset) when start/end are given.","Provide periods=N together with start and freq, or end and freq.","Guard the call: if freq is None: freq = 'D' (or raise your own descriptive error) before invoking date_range."],"exampleFix":"// before\npd.date_range('2020-01-01')  # ValueError: Must provide freq argument if no data is supplied\n\n// after\npd.date_range('2020-01-01', freq='D', periods=5)","handlingStrategy":"validation","validationCode":"def safe_date_range(start=None, end=None, periods=None, freq=None):\n    if freq is None and any(x is None for x in [periods, start, end]):\n        freq = \"D\"  # sensible default, or raise\n    return pd.date_range(start=start, end=end, periods=periods, freq=freq)","typeGuard":"def has_minimal_range_args(start, end, periods, freq) -> bool:\n    return freq is not None or not any(x is None for x in [periods, start, end])","tryCatchPattern":"try:\n    rng = pd.date_range(start=start, periods=periods)\nexcept ValueError as e:\n    if \"Must provide freq\" in str(e):\n        rng = pd.date_range(start=start, periods=periods, freq=\"D\")\n    else:\n        raise","preventionTips":["Default freq explicitly when start/end may be missing.","Validate the (start,end,periods,freq) tuple before calling date_range.","Wrap date_range in a project helper that enforces required args."],"tags":["pandas","date-range","frequency","validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}