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 SANDWICH model fit() in qlib/contrib/model/pytorch_sandwich.py:314 when the train or valid DataFrame returned by dataset.prepare(['train','valid','test'], ...) is empty. This is a data/config guard: it means the DatasetH segments produced zero rows (bad date ranges, missing instruments, or wrong segment names), not a model bug.
Source
Thrown at qlib/contrib/model/pytorch_sandwich.py:314
score = self.metric_fn(pred, label)
scores.append(score.item())
return np.mean(losses), np.mean(scores)
def fit(
self,
dataset: DatasetH,
evals_result=dict(),
save_path=None,
):
df_train, df_valid, df_test = dataset.prepare(
["train", "valid", "test"],
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.")
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"] = []
# train
self.logger.info("training...")
self.fitted = True
for step in range(self.n_epochs):
self.logger.info("Epoch%d:", step)View on GitHub (pinned to 79633dd950)
Solutions
- Inspect dataset.prepare('train', col_set=['feature','label']) yourself in a REPL to see which segment is empty and why.
- Fix segment date ranges in the handler/dataset config so they overlap the dumped data calendar.
- Run qlib.init() with the correct provider_uri and verify data exists with qlib.data.calendar and instrument checking.
- Register custom segment names on the DatasetH (kwargs.segments) so prepare can resolve them.
Example fix
# before segments: train: [2010-01-01, 2020-12-31] # data dump ends 2018 # after segments: train: [2010-01-01, 2016-12-31] valid: [2017-01-01, 2018-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"Segment '{seg}' is empty; fix handler/dataset config before fit()") Try / catch
try:
model.fit(dataset)
except ValueError as e:
if "Empty data" in str(e):
for seg in ("train", "valid"):
print(seg, dataset.prepare(seg, col_set=["feature", "label"]).shape)
raise
raise Prevention
- Smoke-test each segment with dataset.prepare(...).empty before launching long training runs.
- Keep segment boundaries within the dumped data calendar (verify with qlib.calendar).
- Always qlib.init() with a provider_uri you have verified contains your instruments.
When it happens
Trigger: Workflow handler_config with date ranges outside the dumped bin data; segments named differently than what the dataset defines (prepare returns empty); an expression filter that drops all samples; forgetting qlib.dump_bin / using an uninitialized provider so no data is found.
Common situations: Wrong calendar (e.g. CSI300 dates against a CSI500 dump); train/valid segments swapped with custom names never registered in DatasetH; learning/valid boundaries set beyond the data end date; running without qlib.init() or with a broken provider URI.
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/76cf1ea96ff27271.
Report an issue: GitHub.