{"record":{"id":"bd38b96acd9f1aa2","repo":"microsoft/qlib","slug":"empty-data-from-dataset-please-check-your-dataset-bd38b9","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_sfm.py","lineNumber":372,"sourceCode":"\n            self.train_optimizer.zero_grad()\n            loss.backward()\n            torch.nn.utils.clip_grad_value_(self.sfm_model.parameters(), 3.0)\n            self.train_optimizer.step()\n\n    def fit(\n        self,\n        dataset: DatasetH,\n        evals_result=dict(),\n        save_path=None,\n    ):\n        df_train, df_valid = dataset.prepare(\n            [\"train\", \"valid\"],\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        x_train, y_train = df_train[\"feature\"], df_train[\"label\"]\n        x_valid, y_valid = df_valid[\"feature\"], df_valid[\"label\"]\n\n        save_path = get_or_create_path(save_path)\n        stop_steps = 0\n        train_loss = 0\n        best_score = -np.inf\n        best_epoch = 0\n        evals_result[\"train\"] = []\n        evals_result[\"valid\"] = []\n\n        # train\n        self.logger.info(\"training...\")\n        self.fitted = True\n\n        for step in range(self.n_epochs):\n            self.logger.info(\"Epoch%d:\", step)\n            self.logger.info(\"training...\")","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/model/pytorch_sfm.py#L354-L390","documentation":"Raised by SFM model fit() in qlib/contrib/model/pytorch_sfm.py:372 when dataset.prepare(['train','valid']) yields an empty train or valid DataFrame. It is a data sanity guard identical in spirit to the other pytorch contrib models: zero rows in a segment means the dataset/handler config does not intersect the available data, and training cannot proceed.","triggerScenarios":"Segments whose date ranges fall outside the data dump's calendar; expression filters in the handler that eliminate all rows; wrong provider_uri / missing qlib.init; segment names not defined in the DatasetH.","commonSituations":"Valid segment set past the last dumped date; custom instruments file with codes absent from the dump; running examples against a different market than the data downloaded.","solutions":["Print dataset.prepare('train', col_set=['feature','label']) and .empty for both segments to identify the empty one.","Align segment boundaries with the data calendar (check via qlib.calendar).","Verify qlib.init(provider_uri=...) points at a valid dumped dataset and instruments exist.","Register custom segments in DatasetH if you reference non-default segment names."],"exampleFix":"# before\nvalid: [2019-01-01, 2022-12-31]   # dump ends 2020\n\n# after\nvalid: [2018-01-01, 2020-12-31]","handlingStrategy":"validation","validationCode":"for seg in (\"train\", \"valid\"):\n    df = dataset.prepare(seg, col_set=[\"feature\", \"label\"], data_key=\"learn\")\n    if df.empty:\n        raise ValueError(f\"SFM fit(): segment '{seg}' empty — check date ranges, instruments, provider_uri\")","typeGuard":null,"tryCatchPattern":"try:\n    model.fit(dataset)\nexcept ValueError as e:\n    if \"Empty data\" in str(e):\n        print({s: dataset.prepare(s, col_set=[\"feature\", \"label\"]).shape for s in (\"train\", \"valid\")})\n        raise\n    raise","preventionTips":["Validate segments against the data calendar before training.","Confirm provider_uri is initialized and contains your instrument universe.","Prefer explicit segment tuples in DatasetH over ad-hoc names."],"tags":["qlib","dataset","empty-data","config","data-validation","sfm"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}