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 by DatetimeArray._generate_range when freq is None and at least one of periods/start/end is also None. With no frequency and no full (start,end,periods) triple, the range cannot be generated; this fires before the 'exactly three' check to give the most actionable message.
Solutions
- Provide freq='D' (or another offset) when start/end are given.
- Provide periods=N together with start and freq, or end and freq.
- Guard the call: if freq is None: freq = 'D' (or raise your own descriptive error) before invoking date_range.
Example fix
// before
pd.date_range('2020-01-01') # ValueError: Must provide freq argument if no data is supplied
// after
pd.date_range('2020-01-01', freq='D', periods=5) Defensive patterns
Strategy: validation
Validate before calling
def safe_date_range(start=None, end=None, periods=None, freq=None):
if freq is None and any(x is None for x in [periods, start, end]):
freq = "D" # sensible default, or raise
return pd.date_range(start=start, end=end, periods=periods, freq=freq) Type guard
def has_minimal_range_args(start, end, periods, freq) -> bool:
return freq is not None or not any(x is None for x in [periods, start, end]) Try / catch
try:
rng = pd.date_range(start=start, periods=periods)
except ValueError as e:
if "Must provide freq" in str(e):
rng = pd.date_range(start=start, periods=periods, freq="D")
else:
raise Prevention
- Default freq explicitly when start/end may be missing.
- Validate the (start,end,periods,freq) tuple before calling date_range.
- Wrap date_range in a project helper that enforces required args.
When it happens
Trigger: pd.date_range() with no arguments; pd.date_range(start='2020-01-01') without freq or periods; pd.date_range(periods=5) with nothing else; any call where freq is missing and the triple is incomplete.
Common situations: Calling date_range inside a helper that conditionally omits freq; passing None through from a config dict; defaulting arguments to None and forgetting the fallback.
Related errors
- Inferred frequency from passed values does not conform to…
- Neither `start` nor `end` can be NaT
- Of the four parameters: start, end, periods, and freq…
- periods must be an integer, got
- 'unit' must be one of 's', 'ms', 'us', 'ns'
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/0a68bb2741d2d115.
Report an issue: GitHub.
Appendix: 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 3b7651241d)