{"record":{"id":"85e198f12963e6b5","repo":"microsoft/qlib","slug":"empty-data-from-dataset-please-check-your-dataset-85e198","errorCode":null,"errorMessage":"Empty data from dataset, please check your dataset config.","messagePattern":"Empty data from dataset, please check your dataset config\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/model/pytorch_lstm_ts.py","lineNumber":205,"sourceCode":"            loss = self.loss_fn(pred, label, weight.to(self.device))\n            losses.append(loss.item())\n\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,\n        evals_result=dict(),\n        save_path=None,\n        reweighter=None,\n    ):\n        dl_train = dataset.prepare(\"train\", col_set=[\"feature\", \"label\"], data_key=DataHandlerLP.DK_L)\n        dl_valid = dataset.prepare(\"valid\", col_set=[\"feature\", \"label\"], data_key=DataHandlerLP.DK_L)\n        if dl_train.empty or dl_valid.empty:\n            raise ValueError(\"Empty data from dataset, please check your dataset config.\")\n\n        dl_train.config(fillna_type=\"ffill+bfill\")  # process nan brought by dataloader\n        dl_valid.config(fillna_type=\"ffill+bfill\")  # process nan brought by dataloader\n\n        if reweighter is None:\n            wl_train = np.ones(len(dl_train))\n            wl_valid = np.ones(len(dl_valid))\n        elif isinstance(reweighter, Reweighter):\n            wl_train = reweighter.reweight(dl_train)\n            wl_valid = reweighter.reweight(dl_valid)\n        else:\n            raise ValueError(\"Unsupported reweighter type.\")\n\n        train_loader = DataLoader(\n            ConcatDataset(dl_train, wl_train),\n            batch_size=self.batch_size,\n            shuffle=True,\n            num_workers=self.n_jobs,","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_lstm_ts.py#L187-L223","documentation":"The TS LSTM fit() prepares 'train' and 'valid' as TSDataSampler-style handlers (data_key=DK_L) and requires both non-empty before configuring fillna and building DataLoaders. If either is empty it raises ValueError('Empty data from dataset, please check your dataset config.') — commonly caused by step_len/windowing producing no samples or segment ranges outside the data.","triggerScenarios":"model.fit(dataset) where dataset.prepare('train'|'valid', col_set=['feature','label'], data_key=DK_L).empty is True — segment dates disjoint from the data calendar, handler with no data, or time-series windowing yielding zero samples.","commonSituations":"Segments beyond the handler's end date; dataset built on a calendar where the valid window contains no trading days; all instruments dropped from the handler; misconfigured start/end times in the underlying data handler.","solutions":["Check both prepared handlers' lengths (len(dataset.prepare('train', col_set=['feature','label'], data_key='learn'))) to identify which is empty.","Realign segment windows with the handler's actual date coverage (inspect the handler's underlying index).","Ensure the data handler itself has data (fetch and check shape) and the instruments were not all filtered out.","For TS datasets, confirm the window/step_len leaves at least one sample per segment."],"exampleFix":"# before\ndataset = DatasetH(handler, segments={'train': ('2017-01-01','2017-12-31'), 'valid': ('2018-01-01','2018-06-30')})\n# data only starts 2019 -> dl_train.empty\nmodel.fit(dataset)  # ValueError: Empty data\n\n# after\ndataset = DatasetH(handler, segments={'train': ('2019-01-01','2019-10-31'), 'valid': ('2019-11-01','2019-12-31')})\nmodel.fit(dataset)","handlingStrategy":"validation","validationCode":"for seg in (\"train\", \"valid\"):\n    dl = dataset.prepare(seg, col_set=[\"feature\", \"label\"], data_key=\"learn\")\n    if getattr(dl, \"empty\", False) or len(dl) == 0:\n        raise ValueError(f\"'{seg}' prepared 0 samples; fix segments/windowing config\")","typeGuard":null,"tryCatchPattern":"try:\n    model.fit(dataset)\nexcept ValueError as e:\n    if \"Empty data\" in str(e):\n        # inspect prepare('train')/prepare('valid') sizes; fix date windows\n        raise\n    raise","preventionTips":["For TS datasets, ensure each segment window is long enough for the lookback window.","Verify segment dates intersect the handler calendar.","Log len() of each prepared segment before fit in experiment harnesses."],"tags":["pytorch","qlib","dataset","data-config","lstm","time-series"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}