pandas-dev/pandas · error · ValueError
Must provide freq argument if no data is supplied
Error message
Must provide freq argument if no data is supplied
What it means
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.
Source
Thrown at pandas/core/arrays/datetimes.py:406
@classmethod
def _generate_range(
cls,
start,
end,
periods: int | None,
freq,
tz=None,
normalize: bool = False,
ambiguous: TimeAmbiguous = "raise",
nonexistent: TimeNonexistent = "raise",
inclusive: IntervalClosedType = "both",
*,
unit: TimeUnit = "ns",
) -> Self:
periods = dtl.validate_periods(periods)
if freq is None and any(x is None for x in [periods, start, end]):
raise ValueError("Must provide freq argument if no data is supplied")
if com.count_not_none(start, end, periods, freq) != 3:
raise ValueError(
"Of the four parameters: start, end, periods, "
"and freq, exactly three must be specified"
)
freq = to_offset(freq)
if start is not None:
start = Timestamp(start)
if end is not None:
end = Timestamp(end)
if start is NaT or end is NaT:
raise ValueError("Neither `start` nor `end` can be NaT")
if unit is not None:View on GitHub (pinned to 71959b8cb9)
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.
Example fix
# before pd.date_range(start='2020-01-01') # after pd.date_range(start='2020-01-01', periods=5, freq='D')
Defensive patterns
Strategy: validation
Validate before calling
if freq is None and any(x is None for x in (start, end, periods)):
raise ValueError('freq required when any of start/end/periods is missing') Try / catch
try:
pd.date_range(start=start, end=end, periods=periods, freq=freq)
except ValueError as e:
if 'Must provide freq' in str(e):
pd.date_range(start=start, end=end, periods=periods, freq='D')
else: raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Inferred frequency {inferred} from passed values does not co
- periods must be an integer, got {periods}
- Of the four parameters: start, end, periods, and freq, exact
- Neither `start` nor `end` can be NaT
- Must specify a valid frequency: {freq}
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/0a68bb2741d2d115.
Report an issue: GitHub.