{"record":{"id":"927e76d34c4d52c7","repo":"microsoft/qlib","slug":"empty-data-from-dataset-please-check-your-dataset-927e76","errorCode":null,"errorMessage":"Empty data from dataset, please check your dataset config.","messagePattern":"Empty data from dataset, please check your dataset config\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_hist.py","lineNumber":256,"sourceCode":"\n                score = self.metric_fn(pred, label)\n                scores.append(score.item())\n\n        return np.mean(losses), np.mean(scores)\n\n    def fit(\n        self,\n        dataset: DatasetH,\n        evals_result=dict(),\n        save_path=None,\n    ):\n        df_train, df_valid, df_test = dataset.prepare(\n            [\"train\", \"valid\", \"test\"],\n            col_set=[\"feature\", \"label\"],\n            data_key=DataHandlerLP.DK_L,\n        )\n        if df_train.empty or df_valid.empty:\n            raise ValueError(\"Empty data from dataset, please check your dataset config.\")\n\n        if not os.path.exists(self.stock2concept):\n            url = \"https://github.com/SunsetWolf/qlib_dataset/releases/download/v0/qlib_csi300_stock2concept.npy\"\n            urllib.request.urlretrieve(url, self.stock2concept)\n\n        stock_index = np.load(self.stock_index, allow_pickle=True).item()\n        df_train[\"stock_index\"] = 733\n        df_train[\"stock_index\"] = df_train.index.get_level_values(\"instrument\").map(stock_index)\n        df_valid[\"stock_index\"] = 733\n        df_valid[\"stock_index\"] = df_valid.index.get_level_values(\"instrument\").map(stock_index)\n\n        x_train, y_train, stock_index_train = df_train[\"feature\"], df_train[\"label\"], df_train[\"stock_index\"]\n        x_valid, y_valid, stock_index_valid = df_valid[\"feature\"], df_valid[\"label\"], df_valid[\"stock_index\"]\n\n        save_path = get_or_create_path(save_path)\n\n        stop_steps = 0\n        best_score = -np.inf","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_hist.py#L238-L274","documentation":"Thrown by HISTModel.fit when the train or valid segment prepared from the DatasetH is empty. dataset.prepare(['train','valid','test'], col_set=['feature','label'], data_key=DK_L) returned a DataFrame with zero rows for at least one of train/valid, so there is nothing to train on. The library treats this as a dataset configuration problem, not a model problem.","triggerScenarios":"Calling model.fit(dataset) where the dataset's train or valid segment has no data after handler processing: date range of segments outside the loaded data calendar, instruments with no records, or a DataHandler label processor (DK_L) that drops/filters every row.","commonSituations":"Wrong segment dates in DatasetH (e.g. train start after data end), missing bin/expression data for all instruments, an Alpha158 handler whose label columns are all NaN and get dropped, or forgetting to run dump_bin/dump_pickle so the underlying qlib data is empty.","solutions":["Inspect dataset.prepare('train', col_set=['feature','label']) and dataset.prepare('valid', ...) interactively and confirm both are non-empty","Fix the segment date ranges in your DatasetH config so they overlap the data calendar (check with D.calendar freq='day')","Verify the underlying data exists: qlib.init with the correct provider_uri and confirm instruments resolve to rows (D.list_instruments / D.features on one instrument)","Check that your label expression (e.g. Ref($close,-2)/Ref($close,-1)-1) yields non-NaN values inside the segments"],"exampleFix":"# before\ndataset = DatasetH(handler, segments={\"train\": (20200101, 20201231)})  # data ends 2019\nmodel.fit(dataset)\n\n# after\ndataset = DatasetH(handler, segments={\"train\": (20170101, 20181231), \"valid\": (20190101, 20191231)})\nassert not dataset.prepare('train', col_set='feature').empty\nmodel.fit(dataset)","handlingStrategy":"validation","validationCode":"for seg in (\"train\", \"valid\"):\n    df = dataset.prepare(seg, col_set=[\"feature\", \"label\"], data_key=DataHandlerLP.DK_L)\n    if df.empty:\n        raise RuntimeError(f\"segment '{seg}' is empty; check segments/instruments/data dump\")","typeGuard":null,"tryCatchPattern":"try:\n    model.fit(dataset)\nexcept ValueError as e:\n    if \"Empty data from dataset\" in str(e):\n        raise RuntimeError(\"Dataset segments empty; fix DatasetH config\") from e\n    raise","preventionTips":["Always assert train/valid prepared frames are non-empty before fit","Cross-check segment boundaries against D.calendar before building DatasetH","Run a smoke test: D.features(instruments, ['$close'], start, end) returns rows"],"tags":["qlib","dataset-config","training-data","validation"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}