microsoft/qlib · error · ValueError
metric must be dict or pd.Series
Error message
metric must be dict or pd.Series
What it means
Error "metric must be dict or pd.Series" thrown in microsoft/qlib.
Source
Thrown at qlib/backtest/high_performance_ds.py:517
elif isinstance(other, self.__class__):
return self.__class__(self.metric < other.metric)
else:
return NotImplemented
def __len__(self):
return len(self.metric)
class PandasSingleMetric(SingleMetric):
"""Each SingleMetric is based on pd.Series."""
def __init__(self, metric: Union[dict, pd.Series] = {}):
if isinstance(metric, dict):
self.metric = pd.Series(metric)
elif isinstance(metric, pd.Series):
self.metric = metric
else:
raise ValueError(f"metric must be dict or pd.Series")
def sum(self):
return self.metric.sum()
def mean(self):
return self.metric.mean()
def count(self):
return self.metric.count()
def abs(self):
return self.__class__(self.metric.abs())
@property
def empty(self):
return self.metric.empty
@propertyView on GitHub (pinned to 79633dd950)
Solutions
- Pass the metric as a dict or a pd.Series; other types are not accepted.
- Convert your metric data with pd.Series(...) or dict(...) before passing it.
When it happens
Trigger: This error is raised at qlib/backtest/high_performance_ds.py:517 when the guard condition fails: "metric must be dict or pd.Series". 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/a5314721d288bd72.
Report an issue: GitHub.