{"record":{"id":"55932a2997133ac3","repo":"microsoft/qlib","slug":"method-is-not-supported","errorCode":null,"errorMessage":"{method} is not supported","messagePattern":"(.+?) is not supported","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/high_performance_ds.py","lineNumber":204,"sourceCode":"        # FIXME: why not call the method of data directly?\n        if method == \"sum\":\n            return np.nansum(data)\n        elif method == \"mean\":\n            return np.nanmean(data)\n        elif method == \"last\":\n            # FIXME: I've never seen that this method was called.\n            # Please merge it with \"ts_data_last\"\n            return data[-1]\n        elif method == \"all\":\n            return data.all()\n        elif method == \"ts_data_last\":\n            valid_data = data.loc[~data.isna().data.astype(bool)]\n            if len(valid_data) == 0:\n                return None\n            else:\n                return valid_data.iloc[-1]\n        else:\n            raise ValueError(f\"{method} is not supported\")\n\n\nclass BaseSingleMetric:\n    \"\"\"\n    The data structure of the single metric.\n    The following methods are used for computing metrics in one indicator.\n    \"\"\"\n\n    def __init__(self, metric: Union[dict, pd.Series]):\n        \"\"\"Single data structure for each metric.\n\n        Parameters\n        ----------\n        metric : Union[dict, pd.Series]\n            keys/index is stock_id, value is the metric value.\n            for example:\n                SH600068    NaN\n                SH600079    1.0","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/high_performance_ds.py#L186-L222","documentation":"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\".","triggerScenarios":"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).","commonSituations":"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.","solutions":["Use one of the supported strings: \"sum\", \"mean\", \"last\", \"all\", \"ts_data_last\", or method=None to get the raw IndexData","For aggregations NumpyQuote lacks, fetch with method=None and aggregate yourself on the returned IndexData/np.ndarray","If you control the subclass, extend _agg_data with your method in a custom NumpyQuote subclass"],"exampleFix":"# before\nv = quote.get_data(\"SH600000\", t0, t1, \"$close\", method=\"first\")\n# after\ndata = quote.get_data(\"SH600000\", t0, t1, \"$close\", method=None)\nv = None if data is None or data.empty else data.iloc[0]","handlingStrategy":"validation","validationCode":"SUPPORTED = {None, 'sum', 'mean', 'last', 'all', 'ts_data_last'}\nassert method in SUPPORTED, f\"method {method!r} not supported by NumpyQuote._agg_data; use one of {SUPPORTED}\"","typeGuard":"def is_supported_agg(method) -> bool:\n    return method in {None, 'sum', 'mean', 'last', 'all', 'ts_data_last'}","tryCatchPattern":"try:\n    v = quote.get_data(sid, t0, t1, field, method=method)\nexcept ValueError as e:\n    if \"is not supported\" in str(e):\n        data = quote.get_data(sid, t0, t1, field, method=None)  # aggregate manually\n    else:\n        raise","preventionTips":["Pass method=None and aggregate the returned IndexData yourself for anything beyond the five whitelisted verbs","Do not pass callables to NumpyQuote.get_data; only strings","Prefer 'ts_data_last' over 'last' (the latter is flagged untested in a FIXME)"],"tags":["python","qlib","validation","aggregation","backtest"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}