{"record":{"id":"a5314721d288bd72","repo":"microsoft/qlib","slug":"metric-must-be-dict-or-pd-series","errorCode":null,"errorMessage":"metric must be dict or pd.Series","messagePattern":"metric must be dict or pd\\.Series","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/high_performance_ds.py","lineNumber":517,"sourceCode":"        elif isinstance(other, self.__class__):\n            return self.__class__(self.metric < other.metric)\n        else:\n            return NotImplemented\n\n    def __len__(self):\n        return len(self.metric)\n\n\nclass PandasSingleMetric(SingleMetric):\n    \"\"\"Each SingleMetric is based on pd.Series.\"\"\"\n\n    def __init__(self, metric: Union[dict, pd.Series] = {}):\n        if isinstance(metric, dict):\n            self.metric = pd.Series(metric)\n        elif isinstance(metric, pd.Series):\n            self.metric = metric\n        else:\n            raise ValueError(f\"metric must be dict or pd.Series\")\n\n    def sum(self):\n        return self.metric.sum()\n\n    def mean(self):\n        return self.metric.mean()\n\n    def count(self):\n        return self.metric.count()\n\n    def abs(self):\n        return self.__class__(self.metric.abs())\n\n    @property\n    def empty(self):\n        return self.metric.empty\n\n    @property","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/high_performance_ds.py#L499-L535","documentation":"Error \"metric must be dict or pd.Series\" thrown in microsoft/qlib.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}