{"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":"exception","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L388-L424","documentation":"Raised in _generate_range when freq is None and at least one of start/end/periods is also None. Without freq there is no stride to generate from, so generating a range needs all anchor information; the check fires before the three-of-four counting so it produces a clearer message.","triggerScenarios":"pd.date_range(start='2020-01-01', periods=None, freq=None); pd.date_range() with no arguments; pd.date_range(end=...) with neither freq nor periods. Reused parameter dict that left freq unset.","commonSituations":"Calling date_range with defaults, expecting a daily stride, but freq is keyword-only and defaults to None in _generate_range. Config-driven calls where freq was omitted. Refactor that introduced a None fallback for freq.","solutions":["Pass a freq (e.g. freq='D', 'h', to_offset('W-MON')).","If you know start+end+periods, supply two of them and let pandas compute freq implicitly is NOT allowed — freq is required when any anchor is missing, so supply it.","When building a one-element range, pass periods=1 and freq."],"exampleFix":"# before\npd.date_range(start='2020-01-01')\n\n# after\npd.date_range(start='2020-01-01', periods=5, freq='D')","handlingStrategy":"validation","validationCode":"if freq is None and any(x is None for x in (start, end, periods)):\n    raise ValueError('freq required when any of start/end/periods is missing')","typeGuard":null,"tryCatchPattern":"try:\n    pd.date_range(start=start, end=end, periods=periods, freq=freq)\nexcept ValueError as e:\n    if 'Must provide freq' in str(e):\n        pd.date_range(start=start, end=end, periods=periods, freq='D')\n    else: raise","preventionTips":["Default freq explicitly in your wrapper (e.g. freq='D') so None never reaches date_range.","Reject empty/None parameter dicts at the config boundary."],"tags":["date-range","frequency","constructor","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}