microsoft/qlib · error · ValueError
Most of samples are dropped. Please check this task: {task}
Error message
Most of samples are dropped. Please check this task: {task} What it means
When a MetaTaskDS (meta-learning dataset for data selection) processes a task in PROC_MODE_FULL, it drops NaN rows from the prepared train/test data. If the test segment loses more than 90% of its rows (or was empty to begin with), the task is judged unusable and this ValueError is raised, naming the offending task.
Source
Thrown at qlib/contrib/meta/data_selection/dataset.py:161
please refer to the docs of _prepare_meta_ipt for detailed explanation.
"""
super().__init__(task, meta_info)
self.fill_method = fill_method
time_perf = self._get_processed_meta_info()
self.processed_meta_input = {"time_perf": time_perf}
# FIXME: memory issue in this step
if mode == MetaTask.PROC_MODE_FULL:
# process metainfo_
ds = self.get_dataset()
# these three lines occupied 70% of the time of initializing MetaTaskDS
d_train, d_test = ds.prepare(["train", "test"], col_set=["feature", "label"])
prev_size = d_test.shape[0]
d_train = d_train.dropna(axis=0)
d_test = d_test.dropna(axis=0)
if prev_size == 0 or d_test.shape[0] / prev_size <= 0.1:
raise ValueError(f"Most of samples are dropped. Please check this task: {task}")
assert (
d_test.groupby("datetime", group_keys=False).size().shape[0] >= 5
), "In this segment, this trading dates is less than 5, you'd better check the data."
sample_time_belong = np.zeros((d_train.shape[0], time_perf.shape[1]))
for i, col in enumerate(time_perf.columns):
# these two lines of code occupied 20% of the time of initializing MetaTaskDS
slc = slice(*d_train.index.slice_locs(start=col[0], end=col[1]))
sample_time_belong[slc, i] = 1.0
# If you want that last month also belongs to the last time_perf
# Assumptions: the latest data has similar performance like the last month
sample_time_belong[sample_time_belong.sum(axis=1) != 1, -1] = 1.0
self.processed_meta_input.update(
dict(
X=d_train["feature"],View on GitHub (pinned to 79633dd950)
Solutions
- Shorten or shift the task's test segment so the label horizon (e.g. learned days) fits inside available data.
- Check the underlying DataHandler output for the offending task: prepare the segment and inspect df.isna().mean() to see whether features or labels produce the NaNs.
- Widen the data coverage (more dates/instruments) for the universe the task uses.
- Catch this per-task and skip the bad task when building a MetaDatasetDS over many tasks.
Example fix
// before
task = {"dataset": {"kwargs": {"segments": {"test": ("2019-01-01", "2020-12-31")}}}} # labels run past data end
// after
task = {"dataset": {"kwargs": {"segments": {"test": ("2019-01-01", "2020-06-30")}}}} # label horizon fits Defensive patterns
Strategy: try-catch
Validate before calling
d_test = task_handler.prepare("test", col_set=["feature", "label"])
prev = d_test.shape[0]
surv = d_test.dropna().shape[0]
if prev == 0 or surv / prev <= 0.1:
logger.warning("task %s drops most samples; adjust segments", task) Try / catch
good_tasks = []
for task in tasks:
try:
mtds = MetaTaskDS(task=task, ...)
good_tasks.append(mtds)
except ValueError as e:
if "Most of samples are dropped" in str(e):
logger.warning("skipping bad task: %s", task)
continue
raise Prevention
- Keep label horizons strictly inside available data for every segment.
- Dry-run dropna() coverage checks per task before building the meta dataset.
- Wrap per-task construction in try/except when iterating over many rolling tasks.
When it happens
Trigger: MetaTaskDS init or prepare where d_test.shape[0]/prev_size <= 0.1 after dropna — e.g. a task whose label window extends past available data, so almost every row has NaN labels.
Common situations: Task templates with test segments near the end of the available data (label horizon overruns the calendar); misconfigured segments in the task dict; instrument universes whose data ends before the segment; handlers producing mostly-NaN features.
Related errors
- This type of input is not supported
- the history of distribution data is not long enough.
- Unknown criterion: {self.criterion}
- Please implement the `count` method
- Please implement the `add` method
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/51af7ad87bd5f6f7.
Report an issue: GitHub.