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
Thrown by HISTModel.fit when the train or valid segment prepared from the DatasetH is empty. dataset.prepare(['train','valid','test'], col_set=['feature','label'], data_key=DK_L) returned a DataFrame with zero rows for at least one of train/valid, so there is nothing to train on. The library treats this as a dataset configuration problem, not a model problem.
Source
Thrown at qlib/contrib/model/pytorch_hist.py:256
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.")
if not os.path.exists(self.stock2concept):
url = "https://github.com/SunsetWolf/qlib_dataset/releases/download/v0/qlib_csi300_stock2concept.npy"
urllib.request.urlretrieve(url, self.stock2concept)
stock_index = np.load(self.stock_index, allow_pickle=True).item()
df_train["stock_index"] = 733
df_train["stock_index"] = df_train.index.get_level_values("instrument").map(stock_index)
df_valid["stock_index"] = 733
df_valid["stock_index"] = df_valid.index.get_level_values("instrument").map(stock_index)
x_train, y_train, stock_index_train = df_train["feature"], df_train["label"], df_train["stock_index"]
x_valid, y_valid, stock_index_valid = df_valid["feature"], df_valid["label"], df_valid["stock_index"]
save_path = get_or_create_path(save_path)
stop_steps = 0
best_score = -np.infView on GitHub (pinned to 79633dd950)
Solutions
- Inspect dataset.prepare('train', col_set=['feature','label']) and dataset.prepare('valid', ...) interactively and confirm both are non-empty
- Fix the segment date ranges in your DatasetH config so they overlap the data calendar (check with D.calendar freq='day')
- Verify the underlying data exists: qlib.init with the correct provider_uri and confirm instruments resolve to rows (D.list_instruments / D.features on one instrument)
- Check that your label expression (e.g. Ref($close,-2)/Ref($close,-1)-1) yields non-NaN values inside the segments
Example fix
# before
dataset = DatasetH(handler, segments={"train": (20200101, 20201231)}) # data ends 2019
model.fit(dataset)
# after
dataset = DatasetH(handler, segments={"train": (20170101, 20181231), "valid": (20190101, 20191231)})
assert not dataset.prepare('train', col_set='feature').empty
model.fit(dataset) Defensive patterns
Strategy: validation
Validate before calling
for seg in ("train", "valid"):
df = dataset.prepare(seg, col_set=["feature", "label"], data_key=DataHandlerLP.DK_L)
if df.empty:
raise RuntimeError(f"segment '{seg}' is empty; check segments/instruments/data dump") Try / catch
try:
model.fit(dataset)
except ValueError as e:
if "Empty data from dataset" in str(e):
raise RuntimeError("Dataset segments empty; fix DatasetH config") from e
raise Prevention
- Always assert train/valid prepared frames are non-empty before fit
- Cross-check segment boundaries against D.calendar before building DatasetH
- Run a smoke test: D.features(instruments, ['$close'], start, end) returns rows
When it happens
Trigger: Calling model.fit(dataset) where the dataset's train or valid segment has no data after handler processing: date range of segments outside the loaded data calendar, instruments with no records, or a DataHandler label processor (DK_L) that drops/filters every row.
Common situations: Wrong segment dates in DatasetH (e.g. train start after data end), missing bin/expression data for all instruments, an Alpha158 handler whose label columns are all NaN and get dropped, or forgetting to run dump_bin/dump_pickle so the underlying qlib data is empty.
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.
- {freq} is not supported in NumpyQuote
- {method} is not supported
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/927e76d34c4d52c7.
Report an issue: GitHub.