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 at the top of DNNModelPytorch.fit when either the "train" or "valid" segment prepared from the dataset is an empty DataFrame. The model requires both segments to be non-empty before it builds DataLoaders, so an empty validation split is fatal here (unlike some other qlib models that tolerate a missing valid segment). It is a dataset/segment configuration guard, not a training-time failure.

Source

Thrown at qlib/contrib/model/pytorch_general_nn.py:249

                scores.append(score.item())

        return np.mean(losses), np.mean(scores)

    def fit(
        self,
        dataset: Union[DatasetH, TSDatasetH],
        evals_result=dict(),
        save_path=None,
        reweighter=None,
    ):
        ists = isinstance(dataset, TSDatasetH)  # is this time series dataset

        dl_train = dataset.prepare("train", col_set=["feature", "label"], data_key=DataHandlerLP.DK_L)
        dl_valid = dataset.prepare("valid", col_set=["feature", "label"], data_key=DataHandlerLP.DK_L)
        self.logger.info(f"Train samples: {len(dl_train)}")
        self.logger.info(f"Valid samples: {len(dl_valid)}")
        if dl_train.empty or dl_valid.empty:
            raise ValueError("Empty data from dataset, please check your dataset config.")

        if reweighter is None:
            wl_train = np.ones(len(dl_train))
            wl_valid = np.ones(len(dl_valid))
        elif isinstance(reweighter, Reweighter):
            wl_train = reweighter.reweight(dl_train)
            wl_valid = reweighter.reweight(dl_valid)
        else:
            raise ValueError("Unsupported reweighter type.")

        # Preprocess for data.  To align to Dataset Interface for DataLoader
        if ists:
            dl_train.config(fillna_type="ffill+bfill")  # process nan brought by dataloader
            dl_valid.config(fillna_type="ffill+bfill")  # process nan brought by dataloader
        else:
            # If it is a tabular, we convert the dataframe to numpy to be indexable by DataLoader
            dl_train = dl_train.values
            dl_valid = dl_valid.values

View on GitHub (pinned to 79633dd950)

Solutions

  1. Check the log lines 'Train samples: N / Valid samples: N' just above the raise; whichever is 0 is the broken segment.
  2. Align dataset segments (train/valid/test date ranges) with the calendar of your dumped bin data.
  3. Ensure the segment is named "valid" in DatasetH.setup_seg or kwargs so dfs includes it.
  4. Verify processors/fillna are not removing all rows (inspect dataset.prepare(..., data_key=DataHandlerLP.DK_L).shape).

Example fix

# before
"segments": {
    "train": ("2015-01-01", "2020-12-31"),
    "valid": ("2021-01-01", "2021-12-31"),  # calendar ends 2020 -> empty
}

# after
"segments": {
    "train": ("2015-01-01", "2019-12-31"),
    "valid": ("2020-01-01", "2020-12-31"),
}
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)
    assert not df.empty, f"segment '{seg}' is empty; check dates/calendar/processors"

Prevention

When it happens

Trigger: Calling fit(dataset) where dataset.prepare("train" or "valid", col_set=["feature","label"], data_key=DK_L) returns zero rows: date ranges that do not intersect the data calendar, a "valid" segment key not defined in the dataset, or handlers whose learn-process dropped all rows.

Common situations: Segments specified outside the data's date range (e.g. backtest dates beyond the dump_bin calendar); mislabelled segment names ("validation" instead of "valid"); a filter/processor that drops every row; using a dataset where only train and test segments were defined, forgetting that this model demands a valid segment.

Related errors


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