{"record":{"id":"052db7c2bf5aafa5","repo":"microsoft/qlib","slug":"please-implement-the-get-all-stock-method","errorCode":null,"errorMessage":"Please implement the `get_all_stock` method","messagePattern":"Please implement the `get_all_stock` method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/high_performance_ds.py","lineNumber":36,"sourceCode":"from ..utils.index_data import IndexData, SingleData\nfrom ..utils.resam import resam_ts_data, ts_data_last\nfrom ..utils.time import Freq, is_single_value\n\n\nclass BaseQuote:\n    def __init__(self, quote_df: pd.DataFrame, freq: str) -> None:\n        self.logger = get_module_logger(\"online operator\", level=logging.INFO)\n\n    def get_all_stock(self) -> Iterable:\n        \"\"\"return all stock codes\n\n        Return\n        ------\n        Iterable\n            all stock codes\n        \"\"\"\n\n        raise NotImplementedError(f\"Please implement the `get_all_stock` method\")\n\n    def get_data(\n        self,\n        stock_id: str,\n        start_time: Union[pd.Timestamp, str],\n        end_time: Union[pd.Timestamp, str],\n        field: Union[str],\n        method: Optional[str] = None,\n    ) -> Union[None, int, float, bool, IndexData]:\n        \"\"\"get the specific field of stock data during start time and end_time,\n           and apply method to the data.\n\n           Example:\n            .. code-block::\n                                        $close      $volume\n                instrument  datetime\n                SH600000    2010-01-04  86.778313   16162960.0\n                            2010-01-05  87.433578   28117442.0","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/high_performance_ds.py#L18-L54","documentation":"high_performance_ds.py defines an abstract base for quote storage (used by Exchange when the data fits its vectorized backends). get_all_stock is deliberately unimplemented: every concrete storage class must override it to enumerate stock codes. Hitting this NotImplementedError means a base/abstract instance was used where a concrete implementation was expected.","triggerScenarios":"Instantiating the base quote class directly, or a custom subclass that overrides get_data but not get_all_stock; Exchange then calls get_all_stock during limit/suspension checks and the stub raises.","commonSituations":"Writing a custom high-performance quote backend without implementing the full interface; version upgrades that added abstract methods to the base class, breaking older third-party subclasses.","solutions":["Use a provided concrete backend instead of the base class (the repo ships numpy/vectorized implementations in the same module)","If subclassing, implement get_all_stock to return an iterable of all stock ids in your quote_df","After upgrading qlib, re-check the base class for newly abstracted methods your subclass must provide"],"exampleFix":"# before\nclass MyQuote(BaseQuoteClass):  # get_all_stock not overridden -> NotImplementedError\n    ...\n# after\nclass MyQuote(BaseQuoteClass):\n    def get_all_stock(self):\n        return self.quote_df.index.get_level_values(0).unique()","handlingStrategy":"type-guard","validationCode":"quote = MyQuote(quote_df, freq)\nassert type(quote).get_all_stock is not BaseQuoteClass.get_all_stock, 'get_all_stock not implemented'\nexch = Exchange(freq=freq, quote_df=quote_df)","typeGuard":"def implements_get_all_stock(cls) -> bool:\n    return 'get_all_stock' in cls.__dict__ or any('get_all_stock' in c.__dict__ for c in cls.__mro__[1:-1])","tryCatchPattern":null,"preventionTips":["Never instantiate the base quote class; use shipped vectorized backends","After qlib upgrades, audit custom subclasses for newly abstract methods"],"tags":["qlib","quote-storage","abstract-method","not-implemented"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}