{"record":{"id":"6648b01d99483093","repo":"microsoft/qlib","slug":"please-implement-the-get-data-method","errorCode":null,"errorMessage":"Please implement the `get_data` method","messagePattern":"Please implement the `get_data` method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/high_performance_ds.py","lineNumber":100,"sourceCode":"        start_time : Union[pd.Timestamp, str]\n            closed start time for backtest\n        end_time : Union[pd.Timestamp, str]\n            closed end time for backtest\n        field : str\n            the columns of data to fetch\n        method : Union[str, None]\n            the method apply to data.\n            e.g [None, \"last\", \"all\", \"sum\", \"mean\", \"ts_data_last\"]\n\n        Return\n        ----------\n        Union[None, int, float, bool, IndexData]\n            it will return None in following cases\n            - There is no stock data which meet the query criterion from data source.\n            - The `method` returns None\n        \"\"\"\n\n        raise NotImplementedError(f\"Please implement the `get_data` method\")\n\n\nclass PandasQuote(BaseQuote):\n    def __init__(self, quote_df: pd.DataFrame, freq: str) -> None:\n        super().__init__(quote_df=quote_df, freq=freq)\n        quote_dict = {}\n        for stock_id, stock_val in quote_df.groupby(level=\"instrument\", group_keys=False):\n            quote_dict[stock_id] = stock_val.droplevel(level=\"instrument\")\n        self.data = quote_dict\n\n    def get_all_stock(self):\n        return self.data.keys()\n\n    def get_data(self, stock_id, start_time, end_time, field, method=None):\n        if method == \"ts_data_last\":\n            method = ts_data_last\n        stock_data = resam_ts_data(self.data[stock_id][field], start_time, end_time, method=method)\n        if stock_data is None:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/high_performance_ds.py#L82-L118","documentation":"BaseQuote is an abstract base class for quote-data containers in qlib's high-performance backtest layer. Its get_data(stock_id, start_time, end_time, field, method) method only raises NotImplementedError; every concrete subclass must override it. Hitting this error means you instantiated BaseQuote directly (or a subclass that failed to override get_data) and then queried data.","triggerScenarios":"Calling BaseQuote(quote_df, freq).get_data(...), or passing a BaseQuote-typed object that is not a PandasQuote/NumpyQuote into code that fetches bars (e.g. qlib.backtest exchange/account machinery that calls quote.get_data).","commonSituations":"Custom quote backends that subclass BaseQuote but forget to implement get_data; test code or REPL experiments constructing the base class directly; type-annotated factory code that defaults to BaseQuote instead of a concrete class.","solutions":["Use a concrete implementation: PandasQuote (qlib/backtest/high_performance_ds.py:103) or NumpyQuote (line 128)","If you subclass BaseQuote, implement get_all_stock and get_data with the documented signature (returns None | int | float | bool | IndexData)","Audit custom Quote subclasses with inspect.getmembers to confirm every abstract-style method is overridden before use"],"exampleFix":"// before\nquote = BaseQuote(quote_df, freq=\"day\")\nclose = quote.get_data(\"SH600000\", \"2010-01-04\", \"2010-01-06\", \"$close\")\n// after\nfrom qlib.backtest.high_performance_ds import NumpyQuote\nquote = NumpyQuote(quote_df, freq=\"day\")\nclose = quote.get_data(\"SH600000\", \"2010-01-04\", \"2010-01-06\", \"$close\")","handlingStrategy":"type-guard","validationCode":"from qlib.backtest.high_performance_ds import BaseQuote, PandasQuote, NumpyQuote\nassert type(quote) is not BaseQuote, \"use PandasQuote or NumpyQuote, not BaseQuote\"\nassert isinstance(quote, (PandasQuote, NumpyQuote))","typeGuard":"def is_concrete_quote(q) -> bool:\n    from qlib.backtest.high_performance_ds import BaseQuote, PandasQuote, NumpyQuote\n    return isinstance(q, (PandasQuote, NumpyQuote)) and not type(q) is BaseQuote","tryCatchPattern":null,"preventionTips":["Never instantiate BaseQuote; treat it as an interface only","When subclassing BaseQuote, run inspect.isfunction checks that get_data/get_all_stock are overridden","Keep a single factory that returns PandasQuote/NumpyQuote and type-check its output"],"tags":["python","qlib","abstract-method","not-implemented","backtest"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}