microsoft/qlib · error · NotImplementedError

Please implement the 'assign' method

Error message

Please implement the 'assign' method

What it means

Error "Please implement the 'assign' method" thrown in microsoft/qlib.

Source

Thrown at qlib/backtest/high_performance_ds.py:332

    def assign(self, col: str, metric: Union[dict, pd.Series]) -> None:
        """assign one metric.

        Parameters
        ----------
        col : str
            the metric name of one metric.
        metric : Union[dict, pd.Series]
            one metric with stock_id index, such as deal_amount, ffr, etc.
            for example:
                SH600068    NaN
                SH600079    1.0
                SH600266    NaN
                           ...
                SZ300692    NaN
                SZ300719    NaN,
        """

        raise NotImplementedError(f"Please implement the 'assign' method")

    def transfer(self, func: Callable, new_col: str = None) -> Optional[BaseSingleMetric]:
        """compute new metric with existing metrics.

        Parameters
        ----------
        func : Callable
            the func of computing new metric.
            the kwargs of func will be replaced with metric data by name in this function.
            e.g.
                def func(pa):
                    return (pa > 0).sum() / pa.count()
        new_col : str, optional
            New metric will be assigned in the data if new_col is not None, by default None.

        Return
        ----------
        BaseSingleMetric

View on GitHub (pinned to 79633dd950)

Solutions

  1. Implement the `assign` method in your subclass before calling it.
  2. Use a concrete class that provides `assign` instead of the abstract base.

When it happens

Trigger: This error is raised at qlib/backtest/high_performance_ds.py:332 when the guard condition fails: "Please implement the 'assign' 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/ebb6af208e3364b4. Report an issue: GitHub.