{"record":{"id":"ab3a28ca8297bb33","repo":"pandas-dev/pandas","slug":"of-the-four-parameters-start-end-periods-and-f-ab3a28","errorCode":null,"errorMessage":"Of the four parameters: start, end, periods, and freq, exactly three must be specified","messagePattern":"Of the four parameters: start, end, periods, and freq, exactly three must be specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":305,"sourceCode":"                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)\n        if end is not None and unit is not None:\n            end = end.as_unit(unit, round_ok=False)\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L287-L323","documentation":"TimedeltaArray._generate_range enforces that exactly three of (start, end, periods, freq) are specified. Passing all four, only two, or any other count raises ValueError because the fourth parameter must be left for pandas to compute.","triggerScenarios":"pd.timedelta_range(start, end, periods, freq) all set; pd.timedelta_range(start, end) with only two; pd.timedelta_range(start, periods, freq, end) (over-specified).","commonSituations":"Wrapping timedelta_range in a function that fills every parameter from defaults; passing a freq along with all of start/end/periods because the caller was unsure which to omit.","solutions":["Leave exactly one of the four as None — typically the one you want inferred.","If freq is known, omit either periods or end.","If periods is known, omit either freq or end."],"exampleFix":"// before\npd.timedelta_range('1 day', '5 days', 5, '1D')  # all 4 -> ValueError\n// after\npd.timedelta_range('1 day', '5 days', freq='1D')  # periods inferred","handlingStrategy":"validation","validationCode":"def validate_td_range_args(start, end, periods, freq):\n    import pandas.core.common as com\n    if com.count_not_none(start, end, periods, freq) != 3:\n        raise ValueError('Exactly three of start, end, periods, freq must be set')","typeGuard":"def exactly_three_of_four(start, end, periods, freq) -> bool:\n    import pandas.core.common as com\n    return com.count_not_none(start, end, periods, freq) == 3","tryCatchPattern":"try:\n    pd.timedelta_range(start, end, periods, freq)\nexcept ValueError as e:\n    if 'exactly three must be specified' in str(e):\n        # leave one of the four as None and retry\n        pd.timedelta_range(start=start, end=end, freq=freq)\n    else:\n        raise","preventionTips":["Omit exactly one of start/end/periods/freq.","Validate input arity in wrappers around timedelta_range.","Avoid passing defaults for all four parameters."],"tags":["pandas","timedelta","date-range","argument-validation","arity"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}