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
LSTMModel.fit() prepares train/valid/test in one call, then requires df_train and df_valid to be non-empty; otherwise it raises ValueError('Empty data from dataset, please check your dataset config.') before any training. Empty usually means the segment windows do not intersect the handler's data.
Source
Thrown at qlib/contrib/model/pytorch_lstm.py:216
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
- Reproduce the emptiness: df = dataset.prepare('train', col_set=['feature','label'], data_key='learn'); print(df.shape) — do the same for 'valid'.
- Adjust DatasetH segments (or the handler's start_time/end_time) so both windows contain trading dates present in the data.
- Confirm the handler's underlying dataframe is non-empty (handler.fetch(col_set='feature').shape) and the instruments survive filtering.
- If a processor (e.g. dropna) empties the data, relax it or widen the segments.
Example fix
# before
dataset = DatasetH(handler, segments={'train': ('2018-01-01','2018-12-31'), 'valid': ('2019-01-01','2019-12-31')})
# handler data only covers 2020 -> df_train.empty
model.fit(dataset) # ValueError: Empty data
# after
dataset = DatasetH(handler, segments={'train': ('2020-01-01','2020-06-30'), 'valid': ('2020-07-01','2020-09-30')})
model.fit(dataset) Defensive patterns
Strategy: validation
Validate before calling
df_train, df_valid, _ = dataset.prepare(
["train", "valid", "test"], col_set=["feature", "label"], data_key="learn"
)
assert not df_train.empty, "train segment is empty — check segments vs handler date range"
assert not df_valid.empty, "valid segment is empty — check segments vs handler date range" Try / catch
try:
model.fit(dataset)
except ValueError as e:
if "Empty data" in str(e):
# check dataset.prepare per segment; fix date windows / instruments
raise
raise Prevention
- Print each segment's prepared shape before fit.
- Keep segment windows inside the handler's start_time/end_time coverage.
- Beware calendars: windows with no trading days produce empty frames.
- Check instruments survive filtering and processors don't drop all rows.
When it happens
Trigger: model.fit(dataset) where dataset.prepare(['train','valid','test'], col_set=['feature','label'], data_key=DK_L) yields empty 'train' or 'valid' frames — misaligned segment dates, unloaded instruments, or over-aggressive processors.
Common situations: Segment dates outside the handler's start_time/end_time; calendar mismatch (e.g. data ends before valid segment begins); instruments list empty after filtering; NaN-dropping processors removing all rows.
Related errors
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- optimizer {} is not supported!
- unknown loss `%s`
- unknown metric `%s`
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/66dac720eb1e5566.
Report an issue: GitHub.