{"record":{"id":"a6a9eb25c34cea4f","repo":"pandas-dev/pandas","slug":"must-provide-freq-argument-if-no-data-is-supplied-a6a9eb","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/timedeltas.py","lineNumber":285,"sourceCode":"                # numeric data is interpreted in the dtype's unit, matching\n                #  to_timedelta(data, unit=...); mixed Timedelta/numeric data\n                #  keeps the \"ns\" default, unlike to_timedelta\n                unit = np.datetime_data(dtype)[0]\n\n        data = sequence_to_td64ns(data, copy=copy, unit=unit)\n\n        if dtype is not None:\n            data = astype_overflowsafe(data, dtype=dtype, copy=False)\n\n        return cls._simple_new(data, dtype=data.dtype)\n\n    @classmethod\n    def _generate_range(\n        cls, start, end, periods, freq, closed=None, *, unit: TimeUnit\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\n        if start is not None:\n            start = Timedelta(start).as_unit(\"ns\")\n\n        if end is not None:\n            end = Timedelta(end).as_unit(\"ns\")\n\n        if unit not in [\"s\", \"ms\", \"us\", \"ns\"]:\n            raise ValueError(\"'unit' must be one of 's', 'ms', 'us', 'ns'\")\n\n        if start is not None and unit is not None:\n            start = start.as_unit(unit, round_ok=False)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/timedeltas.py#L267-L303","documentation":"Raised by TimedeltaArray._generate_range when freq is None and at least one of start/end/periods is also None. Generating a timedelta range requires either a frequency to step by, or enough anchor data to infer one; without freq and without full anchor data the sequence is under-specified. This is the first of two validation checks in range generation.","triggerScenarios":"Calling timedelta_range(start='1 day') with neither end, periods, nor freq; or pd.TimedeltaIndex(... ) construction routing into _generate_range with freq=None and a missing anchor. The check at timedeltas.py:284 is `freq is None and any(x is None for x in [periods, start, end])`.","commonSituations":"Programmatically building ranges from partial config; forgetting to pass freq when only one bound is given; defaulting arguments to None and not substituting freq.","solutions":["Provide a freq argument, e.g. timedelta_range(start='1 day', freq='1D', periods=5).","Supply all three of start, end, and periods (freq=None is then inferable).","Validate your config dict before calling: ensure freq is set whenever start or end or periods is absent."],"exampleFix":"# before\npd.timedelta_range(start='1 day')  # ValueError\n# after\npd.timedelta_range(start='1 day', freq='1D', periods=5)","handlingStrategy":"validation","validationCode":"def validate_range_args(start, end, periods, freq):\n    if freq is None and any(x is None for x in (start, end, periods)):\n        raise ValueError('Provide freq when any of start/end/periods is missing')\n    return True","typeGuard":"def has_freq_or_full_anchors(start, end, periods, freq) -> bool:\n    return freq is not None or all(x is not None for x in (start, end, periods))","tryCatchPattern":"try:\n    return pd.timedelta_range(start=start, periods=periods)\nexcept ValueError as e:\n    if 'Must provide freq' in str(e):\n        return pd.timedelta_range(start=start, periods=periods, freq='1D')\n    raise","preventionTips":["Default freq to a sensible value in your builder when anchors are partial.","Validate the four-tuple before calling range constructors.","Document the three-of-four contract in wrapper functions."],"tags":["timedelta","timedelta-range","freq","valueerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}