microsoft/qlib · error · TypeError

Unsupported type

Error message

Unsupported type

What it means

`_parse_fields_info` requires the fields config to be a list or tuple (either a list of expression strings, or a (expressions, names) pair). Passing e.g. a bare string, an int, or a dict element raises TypeError('Unsupported type').

Source

Thrown at qlib/data/dataset/loader.py:100

                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,
        start_time: Union[str, pd.Timestamp] = None,
        end_time: Union[str, pd.Timestamp] = None,
        gp_name: str = None,

View on GitHub (pinned to 79633dd950)

Solutions

  1. Wrap in a list: fields=['$close'].
  2. For grouped configs ensure every value is a list/tuple: {'grp1': ['$close'], 'grp2': [...]}.

Example fix

# before
config = {'price': '$close'}

# after
config = {'price': ['$close', '$volume']}
Defensive patterns

Strategy: type-guard

Validate before calling

def valid_fields_shape(cfg) -> bool:
    if isinstance(cfg, dict):
        return all(valid_fields_shape(v) for v in cfg.values())
    return isinstance(cfg, (list, tuple)) and len(cfg) > 0

Type guard

from typing import Union, List, Tuple

def is_fields_config(v) -> bool:
    if isinstance(v, dict):
        return all(is_fields_config(x) for x in v.values())
    return isinstance(v, (list, tuple)) and len(v) > 0

Prevention

When it happens

Trigger: Passing `fields='$close'` (a single string) instead of a list; a dict per group gone wrong in grouped configs (`config={'grp': '$close'}` instead of `{'grp': ['$close']}`).

Common situations: Config sloppiness: single field passed without brackets; group loaders where one group's value is not a list.

Related errors


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