microsoft/qlib · error · NotImplementedError
Subclass of CalendarStorage must implement `__len__` method
Error message
Subclass of CalendarStorage must implement `__len__` method
What it means
Error "Subclass of CalendarStorage must implement `__len__` method" thrown in microsoft/qlib.
Source
Thrown at qlib/data/storage/storage.py:188
------
ValueError
If the data(storage) does not exist, raise ValueError
"""
raise NotImplementedError(
"Subclass of CalendarStorage must implement `__getitem__(i: int)`/`__getitem__(s: slice)` method"
)
def __len__(self) -> int:
"""
Raises
------
ValueError
If the data(storage) does not exist, raise ValueError
"""
raise NotImplementedError("Subclass of CalendarStorage must implement `__len__` method")
class InstrumentStorage(BaseStorage):
def __init__(self, market: str, freq: str, **kwargs):
self.market = market
self.freq = freq
self.kwargs = kwargs
@property
def data(self) -> Dict[InstKT, InstVT]:
"""get all data
Raises
------
ValueError
If the data(storage) does not exist, raise ValueError
"""
raise NotImplementedError("Subclass of InstrumentStorage must implement `data` method")View on GitHub (pinned to 79633dd950)
Solutions
- Implement the `__len__` method in your CalendarStorage subclass.
- Use the built-in FileCalendarStorage which implements `__len__`.
When it happens
Trigger: This error is raised at qlib/data/storage/storage.py:188 when the guard condition fails: "Subclass of CalendarStorage 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/0f084297ba630691.
Report an issue: GitHub.