microsoft/qlib · error · ValueError
The size of fields must be greater than 0
Error message
The size of fields must be greater than 0
What it means
The data loaders (e.g. QlibDataLoader and friends) parse a `fields` config of the form [expr...] or ([expr...], [names...]). An empty fields list has no expressions to load, so `_parse_fields_info` raises ValueError immediately at loader construction.
Source
Thrown at qlib/data/dataset/loader.py:97
"group_name1": <fields_info1>
"group_name2": <fields_info2>
}
or
<config> := <fields_info>
<fields_info> := ["expr", ...] | (["expr", ...], ["col_name", ...])
# NOTE: list or tuple will be treated as the things when parsing
"""
self.is_group = isinstance(config, dict)
if self.is_group:
self.fields = {grp: self._parse_fields_info(fields_info) for grp, fields_info in config.items()}
else:
self.fields = self._parse_fields_info(config)
def _parse_fields_info(self, fields_info: Union[list, tuple]) -> Tuple[list, list]:
if len(fields_info) == 0:
raise ValueError("The size of fields must be greater than 0")
if not isinstance(fields_info, (list, tuple)):
raise TypeError("Unsupported type")
if isinstance(fields_info[0], str):
exprs = names = fields_info
elif isinstance(fields_info[0], (list, tuple)):
exprs, names = fields_info
else:
raise NotImplementedError(f"This type of input is not supported")
return exprs, names
@abc.abstractmethod
def load_group_df(
self,
instruments,
exprs: list,
names: list,View on GitHub (pinned to 79633dd950)
Solutions
- Provide at least one expression: fields=['$close'] or the (exprs, names) tuple form.
- Guard feature-generation code: raise your own descriptive error when selection returns [].
Example fix
# before
loader_kwargs = {'fields': [], 'names': []}
# after
loader_kwargs = {'fields': ['$close', '$volume'], 'names': ['close', 'volume']} Defensive patterns
Strategy: validation
Validate before calling
def valid_fields_config(fields_info) -> bool:
return isinstance(fields_info, (list, tuple)) and len(fields_info) > 0 Type guard
def is_nonempty_fields(cfg) -> bool:
return bool(cfg) if isinstance(cfg, (list, tuple)) else bool(cfg and all(bool(v) for v in cfg.values())) Prevention
- Assert non-empty fields when configs are generated dynamically.
- Treat an empty feature-selection result as a pipeline error, not a pass-through.
When it happens
Trigger: Passing `data_loader={'class': 'QlibDataLoader', 'kwargs': {'fields': [], ...}}` to DatasetH, or a fields list that a generator/feature-selection step returned empty.
Common situations: Automated feature pruning / selection pipelines that can return zero surviving features; YAML template configs where the fields block was left empty as a placeholder.
Related errors
- fields cannot be empty
- Unsupported type
- This type of input is not supported
- {freq} is not supported in NumpyQuote
- {method} is not supported
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/500abacd6c561504.
Report an issue: GitHub.