microsoft/qlib · error · ValueError
Empty data from dataset, please check your dataset config.
Error message
Empty data from dataset, please check your dataset config.
What it means
Raised by TabNet model fit() in qlib/contrib/model/pytorch_tabnet.py:172 when the train or valid DataFrame from dataset.prepare(['train','valid']) is empty. Standard qlib data guard: it fires before NaN-filling and training, indicating the handler/dataset config produced zero rows for a required segment.
Source
Thrown at qlib/contrib/model/pytorch_tabnet.py:172
evals_result=dict(),
save_path=None,
):
if self.pretrain:
# there is a pretrained model, load the model
self.logger.info("Pretrain...")
self.pretrain_fn(dataset, self.pretrain_file)
self.logger.info("Load Pretrain model")
self.tabnet_model.load_state_dict(torch.load(self.pretrain_file, map_location=self.device))
# adding one more linear layer to fit the final output dimension
self.tabnet_model = FinetuneModel(self.out_dim, self.final_out_dim, self.tabnet_model).to(self.device)
df_train, df_valid = dataset.prepare(
["train", "valid"],
col_set=["feature", "label"],
data_key=DataHandlerLP.DK_L,
)
if df_train.empty or df_valid.empty:
raise ValueError("Empty data from dataset, please check your dataset config.")
df_train.fillna(df_train.mean(), inplace=True)
x_train, y_train = df_train["feature"], df_train["label"]
x_valid, y_valid = df_valid["feature"], df_valid["label"]
save_path = get_or_create_path(save_path)
stop_steps = 0
train_loss = 0
best_score = -np.inf
best_epoch = 0
evals_result["train"] = []
evals_result["valid"] = []
self.logger.info("training...")
self.fitted = True
for epoch_idx in range(self.n_epochs):
self.logger.info("epoch: %s" % (epoch_idx))
self.logger.info("training...")View on GitHub (pinned to 79633dd950)
Solutions
- Check which segment is empty: dataset.prepare('train', col_set=['feature','label']).empty and same for 'valid'.
- Align segment date ranges with the data calendar and instrument universe.
- Verify qlib.init(provider_uri=...) and that the dump contains your instruments.
- If using named segments, ensure DatasetH.segments defines 'train' and 'valid'.
Example fix
# before train: [2008-01-01, 2024-12-31] # dump ends 2020 # after train: [2008-01-01, 2014-12-31] valid: [2015-01-01, 2020-12-31]
Defensive patterns
Strategy: validation
Validate before calling
for seg in ("train", "valid"):
df = dataset.prepare(seg, col_set=["feature", "label"], data_key="learn")
if df.empty:
raise ValueError(f"TabNet fit(): segment '{seg}' empty — check segment config and data dump") Try / catch
try:
model.fit(dataset)
except ValueError as e:
if "Empty data" in str(e):
print({s: dataset.prepare(s, col_set=["feature", "label"]).shape for s in ("train", "valid")})
raise
raise Prevention
- Verify train/valid segments are non-empty before fit(), especially when pretrain segments are also configured.
- Keep segment dates inside the dumped calendar and instruments present in the dump.
- Smoke-test the handler expression on a small date window first.
When it happens
Trigger: Segment dates outside the dumped data calendar; handler expressions filtering out all rows; wrong provider_uri / no qlib.init; also fires after the optional pretrain branch, so pretrain may succeed while the finetune 'train'/'valid' segments are empty.
Common situations: Using pretrain segments that exist but train/valid boundaries misconfigured; examples run against a market different from the downloaded dump; custom instruments missing from the dump.
Related errors
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- invalid memory_mode `{self.memory_mode}`
- Must specify the path to save the dataset.
- Empty data from dataset, please check your dataset config.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/ee762091a18c982d.
Report an issue: GitHub.