microsoft/qlib · error · NotImplementedError
Subclass of InstrumentStorage must implement `__len__` meth
Error message
Subclass of InstrumentStorage must implement `__len__` method
What it means
Error "Subclass of InstrumentStorage must implement `__len__` method" thrown in microsoft/qlib.
Source
Thrown at qlib/data/storage/storage.py:252
ValueError
If the data(storage) does not exist, raise ValueError
"""
raise NotImplementedError("Subclass of InstrumentStorage must implement `__delitem__` method")
def __getitem__(self, k: InstKT) -> InstVT:
"""x.__getitem__(k) <==> x[k]"""
raise NotImplementedError("Subclass of InstrumentStorage must implement `__getitem__` method")
def __len__(self) -> int:
"""
Raises
------
ValueError
If the data(storage) does not exist, raise ValueError
"""
raise NotImplementedError("Subclass of InstrumentStorage must implement `__len__` method")
class FeatureStorage(BaseStorage):
def __init__(self, instrument: str, field: str, freq: str, **kwargs):
self.instrument = instrument
self.field = field
self.freq = freq
self.kwargs = kwargs
@property
def data(self) -> pd.Series:
"""get all data
Notes
------
if data(storage) does not exist, return empty pd.Series: `return pd.Series(dtype=np.float32)`
"""
raise NotImplementedError("Subclass of FeatureStorage must implement `data` method")View on GitHub (pinned to 79633dd950)
Solutions
- Implement the `__len__` method in your InstrumentStorage subclass.
- Use the built-in FileInstrumentStorage which implements `__len__`.
When it happens
Trigger: This error is raised at qlib/data/storage/storage.py:252 when the guard condition fails: "Subclass of InstrumentStorage must implement `__len__` method". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/e1a3ac3bb635b6a4.
Report an issue: GitHub.