microsoft/qlib · error · ValueError

{method} is not supported

Error message

{method} is not supported

What it means

NumpyQuote._agg_data whitelists exactly five aggregation methods: "sum", "mean", "last", "all", and "ts_data_last". Any other non-None method string passed through get_data(stock_id, start_time, end_time, field, method) reaches the else branch and raises ValueError. Note the FIXME at line 191-193: "last" is untested legacy code; prefer "ts_data_last".

Source

Thrown at qlib/backtest/high_performance_ds.py:204

        # FIXME: why not call the method of data directly?
        if method == "sum":
            return np.nansum(data)
        elif method == "mean":
            return np.nanmean(data)
        elif method == "last":
            # FIXME: I've never seen that this method was called.
            # Please merge it with "ts_data_last"
            return data[-1]
        elif method == "all":
            return data.all()
        elif method == "ts_data_last":
            valid_data = data.loc[~data.isna().data.astype(bool)]
            if len(valid_data) == 0:
                return None
            else:
                return valid_data.iloc[-1]
        else:
            raise ValueError(f"{method} is not supported")


class BaseSingleMetric:
    """
    The data structure of the single metric.
    The following methods are used for computing metrics in one indicator.
    """

    def __init__(self, metric: Union[dict, pd.Series]):
        """Single data structure for each metric.

        Parameters
        ----------
        metric : Union[dict, pd.Series]
            keys/index is stock_id, value is the metric value.
            for example:
                SH600068    NaN
                SH600079    1.0

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use one of the supported strings: "sum", "mean", "last", "all", "ts_data_last", or method=None to get the raw IndexData
  2. For aggregations NumpyQuote lacks, fetch with method=None and aggregate yourself on the returned IndexData/np.ndarray
  3. If you control the subclass, extend _agg_data with your method in a custom NumpyQuote subclass

Example fix

# before
v = quote.get_data("SH600000", t0, t1, "$close", method="first")
# after
data = quote.get_data("SH600000", t0, t1, "$close", method=None)
v = None if data is None or data.empty else data.iloc[0]
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {None, 'sum', 'mean', 'last', 'all', 'ts_data_last'}
assert method in SUPPORTED, f"method {method!r} not supported by NumpyQuote._agg_data; use one of {SUPPORTED}"

Type guard

def is_supported_agg(method) -> bool:
    return method in {None, 'sum', 'mean', 'last', 'all', 'ts_data_last'}

Try / catch

try:
    v = quote.get_data(sid, t0, t1, field, method=method)
except ValueError as e:
    if "is not supported" in str(e):
        data = quote.get_data(sid, t0, t1, field, method=None)  # aggregate manually
    else:
        raise

Prevention

When it happens

Trigger: Calling quote.get_data(..., method="first"), method="max", method="std", or any pandas resample-style verb; passing a callable instead of a string (NumpyQuote expects a string, unlike PandasQuote which maps only the literal "ts_data_last" to a function).

Common situations: Porting calls from qlib's online/operator layer or user strategies that assumed arbitrary method names; mixing up NumpyQuote and PandasQuote method semantics (PandasQuote forwards arbitrary method values into resam_ts_data); typo like "ts_data_last " with trailing whitespace.

Related errors


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