microsoft/qlib · error · NotImplementedError

Subclass of FeatureStorage must implement `clear` method

Error message

Subclass of FeatureStorage must implement `clear` method

What it means

FeatureStorage.clear (qlib/data/storage/storage.py:297) is an abstract method that must remove all stored data for the feature. The base class raises NotImplementedError to enforce that every backend defines its own deletion semantics (deleting files, clearing binary segments, dropping DB rows). Calling clear() on the base class or an incomplete subclass raises this error.

Source

Thrown at qlib/data/storage/storage.py:297

        """
        raise NotImplementedError("Subclass of FeatureStorage must implement `start_index` method")

    @property
    def end_index(self) -> Union[int, None]:
        """get FeatureStorage end index

        Notes
        -----
        The  right index of the data range (both sides are closed)

            The next  data appending point will be  `end_index + 1`

        If the data(storage) does not exist, return None
        """
        raise NotImplementedError("Subclass of FeatureStorage must implement `end_index` method")

    def clear(self) -> None:
        raise NotImplementedError("Subclass of FeatureStorage must implement `clear` method")

    def write(self, data_array: Union[List, np.ndarray, Tuple], index: int = None):
        """Write data_array to FeatureStorage starting from index.

        Notes
        ------
            If index is None, append data_array to feature.

            If len(data_array) == 0; return

            If (index - self.end_index) >= 1, self[end_index+1: index] will be filled with np.nan

        Examples
        ---------
            .. code-block::

                feature:
                    3   4

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use a concrete backend such as FileFeatureStorage whose clear() deletes the backing files
  2. Implement clear() in your subclass to remove all persisted data for the feature
  3. If you never clear data, delete the storage files/directories manually instead
  4. Verify the object returned by the storage factory is a concrete class before calling lifecycle methods

Example fix

// before
storage = FeatureStorage(...)  # or incomplete subclass
storage.clear()  # NotImplementedError

// after
class MyStorage(FeatureStorage):
    def clear(self) -> None:
        self._file.unlink(missing_ok=True)
Defensive patterns

Strategy: type-guard

Validate before calling

from qlib.data.storage.storage import FeatureStorage
assert type(storage).clear is not FeatureStorage.clear, 'clear not implemented'

Type guard

def has_concrete_clear(storage) -> bool:
    return type(storage).clear is not FeatureStorage.clear

Try / catch

try:
    storage.clear()
except NotImplementedError:
    logger.warning('storage %s cannot be cleared programmatically; delete files manually', storage)

Prevention

When it happens

Trigger: Calling storage.clear() on a directly instantiated FeatureStorage; a custom backend missing the clear() override; data re-dump pipelines that clear storage before rewriting.

Common situations: Custom backend development where clear was skipped; scripts that wipe qlib data directories feature-by-feature; tests exercising storage lifecycle methods.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/9561691aa1bd0a95. Report an issue: GitHub.