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

  1. Provide freq='D' (or another offset) when start/end are given.
  2. Provide periods=N together with start and freq, or end and freq.
  3. 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

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


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)