microsoft/qlib · critical · ValueError

Empty data from dataset, please check your dataset config.

Error message

Empty data from dataset, please check your dataset config.

What it means

At the start of fit(), ALSTMTSModel prepares both the 'train' and 'valid' segments of the DatasetH and immediately checks .empty on each. If either DataFrame comes back empty, it raises ValueError with this message, because training or early-stopping validation on zero rows is impossible. The root cause is almost always in the dataset configuration (segments date ranges, instruments, handler), not the model.

Source

Thrown at qlib/contrib/model/pytorch_alstm_ts.py:216

                loss = self.loss_fn(pred, label, weight.to(self.device))
                losses.append(loss.item())

                score = self.metric_fn(pred, label)
                scores.append(score.item())

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

    def fit(
        self,
        dataset,
        evals_result=dict(),
        save_path=None,
        reweighter=None,
    ):
        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)
        if dl_train.empty or dl_valid.empty:
            raise ValueError("Empty data from dataset, please check your dataset config.")

        dl_train.config(fillna_type="ffill+bfill")  # process nan brought by dataloader
        dl_valid.config(fillna_type="ffill+bfill")  # process nan brought by dataloader

        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.")

        train_loader = DataLoader(
            ConcatDataset(dl_train, wl_train),
            batch_size=self.batch_size,
            shuffle=True,
            num_workers=self.n_jobs,

View on GitHub (pinned to 79633dd950)

Solutions

  1. Print dataset.prepare('train', col_set=['feature','label']) and the 'valid' equivalent before fit() to see which segment is empty.
  2. Fix the segments in your DatasetH config so train and valid ranges overlap actual data in the underlying QlibDataLoader.
  3. Verify the instruments argument resolves to stock codes that exist in your dumped qlib data directory.
  4. Check handler label/process_drop_rows configuration is not removing every row (e.g. all-NaN labels).

Example fix

# before
segments = {'train': ('2010-01-01', '2012-12-31'), 'valid': ('2030-01-01', '2031-12-31')}

# after
segments = {'train': ('2010-01-01', '2012-12-31'), 'valid': ('2013-01-01', '2014-12-31')}
Defensive patterns

Strategy: validation

Validate before calling

for seg in ('train', 'valid'):
    df = dataset.prepare(seg, col_set=['feature', 'label'], data_key='learn')
    if df.empty:
        raise RuntimeError(f"segment '{seg}' is empty; fix segments/instruments config before fit")

Try / catch

try:
    model.fit(dataset)
except ValueError as e:
    if 'Empty data from dataset' in str(e):
        # inspect dataset.prepare('train'/'valid') and correct segment/instrument config, then retry
        ...
    raise

Prevention

When it happens

Trigger: Calling fit(dataset) where dataset.prepare('train' ...) or dataset.prepare('valid' ...) returns an empty DataFrame: date segment outside the handler's data coverage, an instrument list whose stocks have no data in range, a handler with learn/process labels that drop every row, or a misnamed segment key.

Common situations: Calendaring mistakes such as segments: valid ending before the data starts; using an instrument file for a different market/exchange; a DataHandler config whose label expression yields all-NaN so processed labels drop all rows; switching from alpha158/alpha360 datasets with incompatible date ranges.

Related errors


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