microsoft/qlib · error · ValueError

interval error: {self.interval}

Error message

interval error: {self.interval}

What it means

Raised by YahooCollector.init_datetime (scripts/data_collector/yahoo/collector.py:106) when self.interval is neither INTERVAL_1min nor INTERVAL_1d. Yahoo collection supports only daily and 1-minute bars; init_datetime runs during __init__, so an invalid interval aborts collector construction immediately. Note the earlier branch also clamps 1min start_datetime to DEFAULT_START_DATETIME_1MIN.

Source

Thrown at scripts/data_collector/yahoo/collector.py:106

            start=start,
            end=end,
            interval=interval,
            max_workers=max_workers,
            max_collector_count=max_collector_count,
            delay=delay,
            check_data_length=check_data_length,
            limit_nums=limit_nums,
        )

        self.init_datetime()

    def init_datetime(self):
        if self.interval == self.INTERVAL_1min:
            self.start_datetime = max(self.start_datetime, self.DEFAULT_START_DATETIME_1MIN)
        elif self.interval == self.INTERVAL_1d:
            pass
        else:
            raise ValueError(f"interval error: {self.interval}")

        self.start_datetime = self.convert_datetime(self.start_datetime, self._timezone)
        self.end_datetime = self.convert_datetime(self.end_datetime, self._timezone)

    @staticmethod
    def convert_datetime(dt: [pd.Timestamp, datetime.date, str], timezone):
        try:
            dt = pd.Timestamp(dt, tz=timezone).timestamp()
            dt = pd.Timestamp(dt, tz=tzlocal(), unit="s")
        except ValueError as e:
            pass
        return dt

    @property
    @abc.abstractmethod
    def _timezone(self):
        raise NotImplementedError("rewrite get_timezone")

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use interval='1d' or interval='1min' exactly when instantiating the collector / via --interval.
  2. Reference the class constants (YahooCollector.INTERVAL_1d / INTERVAL_1min) rather than literals.
  3. For other granularities, query yahooquery directly — this collector will not accept them.

Example fix

# before
collector = YahooCollectorCN(..., interval='1h', ...)

# after
collector = YahooCollectorCN(..., interval='1d', ...)
Defensive patterns

Strategy: validation

Validate before calling

from scripts.data_collector.yahoo.collector import YahooCollector
assert interval in (YahooCollector.INTERVAL_1d, YahooCollector.INTERVAL_1min), f'yahoo collector supports only 1d/1min, got {interval}'

Type guard

def is_yahoo_interval(interval: str) -> bool:
    return interval in ('1d', '1min')

Try / catch

try:
    collector = YahooCollectorCN(..., interval=interval)
except ValueError as e:
    if 'interval error' in str(e):
        raise SystemExit("use interval '1d' or '1min'")
    raise

Prevention

When it happens

Trigger: Constructing any YahooCollector subclass with interval outside {INTERVAL_1min ('1min'), INTERVAL_1d ('1d')} — e.g. '5min', '60m', '1week', '1h'. The check happens before timezone conversion, so no request is ever made.

Common situations: Passing native Yahoo Finance interval vocabulary ('1m', '1h', '5m') instead of the collector's own constants; reusing a config from another collector; typos like '1 day'.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/f1ea3ac62d19f162. Report an issue: GitHub.