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 HFMLGBModel._prepare_data when dataset.prepare returns an empty 'train' or 'valid' segment at learn time. This high-frequency model converts labels into cross-sectional alphas (subtracting per-timestamp group means) and then binarizes them into an up/down classification target, which requires non-empty train and valid frames.

Source

Thrown at qlib/contrib/model/highfreq_gdbt_model.py:86

        res = pd.Series(self.model.predict(x_test.values), index=x_test.index)
        y_test["pred"] = res

        up_p, down_p, up_a, down_a = self._cal_signal_metrics(y_test, threhold, 1 - threhold)
        print("===============================")
        print("High frequency signal test")
        print("===============================")
        print("Test set precision: ")
        print("Positive precision: {}, Negative precision: {}".format(up_p, down_p))
        print("Test Alpha Average in test set: ")
        print("Positive average alpha: {}, Negative average alpha: {}".format(up_a, down_a))

    def _prepare_data(self, dataset: DatasetH):
        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.")

        x_train, y_train = df_train["feature"], df_train["label"]
        x_valid, y_valid = df_valid["feature"], df_valid["label"]
        if y_train.values.ndim == 2 and y_train.values.shape[1] == 1:
            l_name = df_train["label"].columns[0]
            # Convert label into alpha
            df_train.loc[:, ("label", l_name)] = (
                df_train.loc[:, ("label", l_name)]
                - df_train.loc[:, ("label", l_name)].groupby(level=0, group_keys=False).mean()
            )
            df_valid.loc[:, ("label", l_name)] = (
                df_valid.loc[:, ("label", l_name)]
                - df_valid.loc[:, ("label", l_name)].groupby(level=0, group_keys=False).mean()
            )

            def mapping_fn(x):
                return 0 if x < 0 else 1

View on GitHub (pinned to 79633dd950)

Solutions

  1. Check dataset.prepare(seg, col_set=["feature","label"], data_key="learn").shape for 'train' and 'valid' before fit
  2. Align handler start_time/end_time with the high-frequency calendar data actually loaded
  3. Loosen or fix processors/instrument filters that eliminate all rows

Example fix

# before
model.fit(dataset)  # ValueError: Empty data from dataset

# after
for seg in ["train", "valid"]:
    assert not dataset.prepare(seg, col_set=["feature","label"], data_key="learn").empty, seg
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="learn")
    assert not df.empty, f"{seg} empty; check high-frequency dataset config"

Prevention

When it happens

Trigger: Calling fit with empty train/valid segments after DK_L processing — e.g. date ranges outside the calendar, an empty instrument universe, or processors dropping all rows.

Common situations: High-frequency (minute-bar) datasets with a narrower calendar than configured; segment dates not overlapping the loaded bins; aggressive NaN filtering on sparse intraday features.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/a6bff1d701b553d6. Report an issue: GitHub.