microsoft/qlib · error · NotImplementedError
Please implement the `get_all_stock` method
Error message
Please implement the `get_all_stock` method
What it means
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.
Source
Thrown at qlib/backtest/high_performance_ds.py:36
from ..utils.index_data import IndexData, SingleData
from ..utils.resam import resam_ts_data, ts_data_last
from ..utils.time import Freq, is_single_value
class BaseQuote:
def __init__(self, quote_df: pd.DataFrame, freq: str) -> None:
self.logger = get_module_logger("online operator", level=logging.INFO)
def get_all_stock(self) -> Iterable:
"""return all stock codes
Return
------
Iterable
all stock codes
"""
raise NotImplementedError(f"Please implement the `get_all_stock` method")
def get_data(
self,
stock_id: str,
start_time: Union[pd.Timestamp, str],
end_time: Union[pd.Timestamp, str],
field: Union[str],
method: Optional[str] = None,
) -> Union[None, int, float, bool, IndexData]:
"""get the specific field of stock data during start time and end_time,
and apply method to the data.
Example:
.. code-block::
$close $volume
instrument datetime
SH600000 2010-01-04 86.778313 16162960.0
2010-01-05 87.433578 28117442.0View on GitHub (pinned to 79633dd950)
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
Example fix
# before
class MyQuote(BaseQuoteClass): # get_all_stock not overridden -> NotImplementedError
...
# after
class MyQuote(BaseQuoteClass):
def get_all_stock(self):
return self.quote_df.index.get_level_values(0).unique() Defensive patterns
Strategy: type-guard
Validate before calling
quote = MyQuote(quote_df, freq) assert type(quote).get_all_stock is not BaseQuoteClass.get_all_stock, 'get_all_stock not implemented' exch = Exchange(freq=freq, quote_df=quote_df)
Type guard
def implements_get_all_stock(cls) -> bool:
return 'get_all_stock' in cls.__dict__ or any('get_all_stock' in c.__dict__ for c in cls.__mro__[1:-1]) Prevention
- Never instantiate the base quote class; use shipped vectorized backends
- After qlib upgrades, audit custom subclasses for newly abstract methods
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Please implement the `get_data` method
- Please implement the `__init__` method
- Subclass of SeriesDFilter must reimplement `getFilterSeries`
- Subclass of FeatureStorage must implement `data` method
- Subclass of FeatureStorage must implement `start_index` meth
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/052db7c2bf5aafa5.
Report an issue: GitHub.