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 at the top of TCTSModel.fit after preparing the train/valid/test segments. If the prepared train or valid DataFrame is empty (zero rows), there is nothing to learn from or validate against, so fit aborts immediately with this ValueError. Note it checks segments prepared with data_key=DK_L (learn-process data).

Source

Thrown at qlib/contrib/model/pytorch_tcts.py:247

            pred = self.fore_model(feature)
            loss = torch.mean((pred - label[:, abs(self.target_label)]) ** 2)
            losses.append(loss.item())

        return np.mean(losses)

    def fit(
        self,
        dataset: DatasetH,
        verbose=True,
        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.")

        x_train, y_train = df_train["feature"], df_train["label"]
        x_valid, y_valid = df_valid["feature"], df_valid["label"]
        x_test, y_test = df_test["feature"], df_test["label"]

        if save_path is None:
            save_path = get_or_create_path(save_path)
        best_loss = np.inf
        while best_loss > self.lowest_valid_performance:
            if best_loss < np.inf:
                print("Failed! Start retraining.")
                self.seed = random.randint(0, 1000)  # reset random seed

            if self.seed is not None:
                np.random.seed(self.seed)
                torch.manual_seed(self.seed)

            best_loss = self.training(

View on GitHub (pinned to 79633dd950)

Solutions

  1. Check the dataset segments: print(dataset.prepare('train').shape) and dataset.prepare('valid').shape and confirm both are non-empty.
  2. Align segment date strings with the data calendar (e.g. shrink/shift 'train'/'valid' start and end into the range covered by the handler's data).
  3. Inspect processors (dropna etc.) — if labels are all NaN in the window, choose a segment where labels exist or adjust the label processor.
  4. Verify the data handler actually loaded data (check underlying df shape / data source config) before fitting.

Example fix

# before
segments = {"train": ("2010-01-01", "2012-12-31"), ...}  # dates absent from loaded data

# after
segments = {"train": ("2017-01-01", "2019-12-31"), ...}  # inside the handler's calendar
assert not dataset.prepare("train").empty and not dataset.prepare("valid").empty
Defensive patterns

Strategy: validation

Validate before calling

df_train = dataset.prepare("train", col_set=["feature", "label"], data_key="learn")
df_valid = dataset.prepare("valid", col_set=["feature", "label"], data_key="learn")
assert not df_train.empty, "train segment is empty — check segment dates/processors"
assert not df_valid.empty, "valid segment is empty — check segment dates/processors"

Try / catch

try:
    model.fit(dataset)
except ValueError as e:
    if "Empty data" in str(e):
        # inspect segments and data calendar, then fix config and retry
        raise RuntimeError("Dataset segments empty; adjust segment dates / processors") from e
    raise

Prevention

When it happens

Trigger: Calling fit(dataset) where dataset.prepare(['train','valid','test'], col_set=['feature','label'])[0 or 1] returns an empty DataFrame: misconfigured date ranges (segments outside the underlying calendar), segments named wrongly, or a handler whose processors dropped every row.

Common situations: Segment dates that don't overlap the loaded bar data (wrong market/exchange calendar, wrong start/end); typo'd segment keys so prepare returns empty; DropnaProcessor/DropnaLabel removing all samples when labels are all-NaN for that window.

Related errors


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