microsoft/qlib · error · ValueError
Empty training data from dataset, please check your dataset
Error message
Empty training data from dataset, please check your dataset config.
What it means
Raised at the start of GRUModel.fit when the prepared train segment is an empty DataFrame. Unlike pytorch_general_nn (which also requires valid), GRU tolerates a missing/empty valid segment (it defaults to None) but hard-fails on empty train data, because there is nothing to optimize.
Source
Thrown at qlib/contrib/model/pytorch_gru.py:229
dataset: DatasetH,
evals_result=dict(),
save_path=None,
):
# prepare training and validation data
dfs = {
k: dataset.prepare(
k,
col_set=["feature", "label"],
data_key=DataHandlerLP.DK_L,
)
for k in ["train", "valid"]
if k in dataset.segments
}
df_train, df_valid = dfs.get("train", pd.DataFrame()), dfs.get("valid", pd.DataFrame())
# check if training data is empty
if df_train.empty:
raise ValueError("Empty training data from dataset, please check your dataset config.")
df_train = df_train.dropna()
x_train, y_train = df_train["feature"], df_train["label"]
# check if validation data is provided
if not df_valid.empty:
df_valid = df_valid.dropna()
x_valid, y_valid = df_valid["feature"], df_valid["label"]
else:
x_valid, y_valid = None, None
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"] = []View on GitHub (pinned to 79633dd950)
Solutions
- Print dataset.prepare('train', col_set=['feature','label'], data_key=DataHandlerLP.DK_L).shape and confirm it is non-empty.
- Adjust train segment dates to overlap the data calendar produced by dump_bin.
- Check instrument filters and processors are not eliminating all rows.
- Ensure the segment key is exactly "train" in the dataset config.
Example fix
# before
"segments": {"train": ("2025-01-01", "2025-12-31")} # data ends 2022 -> empty
# after
"segments": {"train": ("2018-01-01", "2021-12-31")} Defensive patterns
Strategy: validation
Validate before calling
df_train = dataset.prepare("train", col_set=["feature", "label"], data_key=DataHandlerLP.DK_L)
assert not df_train.empty, "train segment is empty; check segment dates and data calendar" Prevention
- Verify prepared train rows before fit; remember the check precedes dropna, so also ensure dropna leaves rows.
- Keep train dates within the dumped data calendar and confirm the segment key is exactly 'train'.
When it happens
Trigger: fit(dataset) where dataset.prepare("train", col_set=["feature","label"], data_key=DK_L) returns zero rows: train date range outside the data calendar, segment misnamed, or all rows dropped. Note the check runs BEFORE dropna, so data that becomes empty only after dropna() produces a different failure downstream (empty tensor batches), not this error.
Common situations: Train segment dates not covered by the dumped binary data; segment key typo such as "Train"; a learn-type processor removing every row; using an instrument universe with no overlapping dates.
Related errors
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
- Empty data from dataset, please check your dataset config.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/5bc4d26e34514ba4.
Report an issue: GitHub.