microsoft/qlib · error · NotImplementedError
Subclass of FeatureStorage must implement `write` method
Error message
Subclass of FeatureStorage must implement `write` method
What it means
FeatureStorage.write (qlib/data/storage/storage.py:352) is the abstract method that persists a data_array starting at a given index (appending when index is None, filling gaps with NaN, ignoring empty arrays). The base class raises NotImplementedError; each backend must define how values are serialized. Calling write() without a concrete subclass implementation triggers this error.
Source
Thrown at qlib/data/storage/storage.py:352
5 6
6 6
7 7
8 np.nan
9 8
>>> self.write([1, np.nan], index=3)
feature:
3 1
4 np.nan
5 6
6 6
7 7
8 np.nan
9 8
"""
raise NotImplementedError("Subclass of FeatureStorage must implement `write` method")
def rebase(self, start_index: int = None, end_index: int = None):
"""Rebase the start_index and end_index of the FeatureStorage.
start_index and end_index are closed intervals: [start_index, end_index]
Examples
---------
.. code-block::
feature:
3 4
4 5
5 6
>>> self.rebase(start_index=4)View on GitHub (pinned to 79633dd950)
Solutions
- Use FileFeatureStorage (or another concrete backend) from the storage factory for writing
- Implement write(data_array, index=None) in your subclass honoring the documented semantics (append, NaN gap fill, skip empty arrays)
- Check the storage class returned by get_storage(...) with isinstance/cls name before writing
- Register your custom backend properly with the storage factory so the correct class is instantiated
Example fix
// before storage = FeatureStorage(instrument, field, freq) storage.write(np.arange(10), index=0) # NotImplementedError // after from qlib.data.storage.file_storage import FileFeatureStorage storage = FileFeatureStorage(instrument, field, freq) storage.write(np.arange(10), index=0)
Defensive patterns
Strategy: type-guard
Validate before calling
from qlib.data.storage.storage import FeatureStorage assert type(storage).write is not FeatureStorage.write, 'write not implemented'
Type guard
def is_writable_storage(storage) -> bool:
return type(storage).write is not FeatureStorage.write Try / catch
try:
storage.write(arr, index=idx)
except NotImplementedError as e:
raise TypeError(f'cannot write via {type(storage).__name__}; use a concrete backend') from e Prevention
- Route writes through the storage factory so concrete classes are selected
- Unit-test write/append/gap-fill behavior for custom backends before integrating
When it happens
Trigger: Calling storage.write(data_array, index) or storage.write(data_array) on the base class; custom backend missing the write() override; dump scripts (e.g. dump_bin.py data writing) that use the storage factory but receive the wrong class.
Common situations: Implementing a new storage backend and finishing read paths first; subclassing FeatureStorage for tests/stubs; mismatches where a factory or config selects an unregistered storage class.
Related errors
- Subclass of FeatureStorage must implement `data` method
- Subclass of FeatureStorage must implement `start_index` meth
- Subclass of FeatureStorage must implement `end_index` method
- Subclass of FeatureStorage must implement `clear` method
- Please implement the `get_all_stock` method
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/70486e965c8011c9.
Report an issue: GitHub.