{"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":302,"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":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L284-L320","documentation":"TimedeltaArray._generate_range requires a freq when constructing a range without complete data. If freq is None and any of periods/start/end is None, pandas cannot synthesize a regular sequence and refuses rather than guess.","triggerScenarios":"pd.timedelta_range(start='1 day', periods=None, freq=None); calling _generate_range(start=None, end=None, periods=5, freq=None); building a range with only two of the four coordinates when freq is absent.","commonSituations":"Dynamically building a range from user input where freq was optional; omitting freq expecting it to be inferred (timedelta does not infer freq).","solutions":["Provide a freq string or DateOffset/Timedelta: pd.timedelta_range(start, periods, freq='1D').","Provide all three of start/end/periods (freq omitted) so the fourth is inferred.","Validate inputs up front and default freq when missing."],"exampleFix":"// before\npd.timedelta_range(start='1 day', periods=None, freq=None)  # ValueError\n// after\npd.timedelta_range(start='1 day', periods=5, freq='1D')","handlingStrategy":"validation","validationCode":"def build_td_range(start=None, end=None, periods=None, freq=None):\n    if freq is None and any(v is None for v in [periods, start, end]):\n        raise ValueError('freq required when any of start/end/periods is missing')\n    return pd.timedelta_range(start=start, end=end, periods=periods, freq=freq)","typeGuard":"def td_range_inputs_valid(start, end, periods, freq) -> bool:\n    return freq is not None or all(v is not None for v in [start, end, periods])","tryCatchPattern":"try:\n    pd.timedelta_range(start=start, end=end, periods=periods, freq=freq)\nexcept ValueError as e:\n    if 'Must provide freq' in str(e):\n        pd.timedelta_range(start=start, end=end, periods=periods, freq='1D')\n    else:\n        raise","preventionTips":["Always supply freq when any of start/end/periods is missing.","Validate user-provided range arguments up front.","Default freq in wrapper functions."],"tags":["pandas","timedelta","date-range","freq","argument-validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}