{"record":{"id":"8655825f3cf32812","repo":"microsoft/qlib","slug":"df-is-empty","errorCode":null,"errorMessage":"df is empty.","messagePattern":"df is empty\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/report/graph.py","lineNumber":52,"sourceCode":"        \"\"\"\n        self._df = df\n\n        self._layout = dict() if layout is None else layout\n        self._graph_kwargs = dict() if graph_kwargs is None else graph_kwargs\n        self._name_dict = name_dict\n\n        self.data = None\n\n        self._init_parameters(**kwargs)\n        self._init_data()\n\n    def _init_data(self):\n        \"\"\"\n\n        :return:\n        \"\"\"\n        if self._df.empty:\n            raise ValueError(\"df is empty.\")\n\n        self.data = self._get_data()\n\n    def _init_parameters(self, **kwargs):\n        \"\"\"\n\n        :param kwargs\n        \"\"\"\n\n        # Instantiate graphics parameters\n        self._graph_type = self._name.lower().capitalize()\n\n        # Displayed column name\n        if self._name_dict is None:\n            self._name_dict = {_item: _item for _item in self._df.columns}\n\n    @staticmethod\n    def get_instance_with_graph_parameters(graph_type: str = None, **kwargs):","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/report/graph.py#L34-L70","documentation":"BaseGraph._init_data (qlib/contrib/report/graph.py) refuses to build a plotly graph from an empty DataFrame. The constructor stores the df, and _init_data immediately raises ValueError('df is empty.') when df.empty is True, because there is nothing to plot and downstream slicing would silently produce blank figures.","triggerScenarios":"Passing an empty pd.DataFrame (zero rows or zero columns) as the df kwarg to any BaseGraph subclass (e.g. ScatterGraph, BarGraph) or to a graph built via BaseGraph.get_instance_with_graph_parameters with df=empty_df.","commonSituations":"Feeding the graph a recorder's prediction/analysis output that came back empty (e.g. no predictions were saved for the segment); filtering a report DataFrame by date/instrument conditions that match nothing; upstream data preparation silently returning an empty frame.","solutions":["Inspect why the DataFrame is empty: check the upstream query (recorder.load_pred, analysis result, date range, instrument filter)","Widen or correct the date/instrument selection so at least one row matches","Guard at the call site: skip plotting when df.empty instead of constructing the graph","If predictions are missing, run signal recording (SignalRecord) before generating report graphs"],"exampleFix":"# before\ngraph = ScatterGraph(df=result_df)\n\n# after\nif result_df.empty:\n    logger.warning('no data to plot; skip')\nelse:\n    graph = ScatterGraph(df=result_df)","handlingStrategy":"validation","validationCode":"if df is None or df.empty:\n    raise ValueError(f'cannot build graph: df has {0 if df is None else len(df)} rows')\ngraph = ScatterGraph(df=df)","typeGuard":"def has_plot_data(df: pd.DataFrame) -> bool:\n    return df is not None and not df.empty and len(df.columns) > 0","tryCatchPattern":"try:\n    graph = ScatterGraph(df=df)\nexcept ValueError as e:\n    if 'empty' in str(e):\n        logger.warning('skipping plot: input dataframe empty')\n    else:\n        raise","preventionTips":["Always assert non-empty input before constructing report graphs","Log the shape of analysis DataFrames at each pipeline stage so emptiness is caught at its origin","Verify the recorder actually saved predictions for the requested segment before plotting"],"tags":["qlib","report","plotly","empty-data"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}