microsoft/qlib · error · NotImplementedError

This type of input is not supported

Error message

This type of input is not supported

What it means

qlib.utils.mod.get_callable_kwargs accepts exactly three config shapes for `config`: a str like 'a.b.c.ClassName' (split into module + class), a dict/Mapping with 'class' and optional 'module_path'/'kwargs', or the class type itself (which must be within accept_types for init_instance_by_config). Anything else — int, list, None, tuple — hits the final else and raises NotImplementedError.

Source

Thrown at qlib/utils/mod.py:115

            m_path, cls = split_module_path(config[key])
            if m_path == "":
                m_path = config.get("module_path", default_module)
            module = get_module_by_module_path(m_path)

            # 2) get callable
            _callable = getattr(module, cls)  # may raise AttributeError
        else:
            _callable = config[key]  # the class type itself is passed in
        kwargs = config.get("kwargs", {})
    elif isinstance(config, str):
        # a.b.c.ClassName
        m_path, cls = split_module_path(config)
        module = get_module_by_module_path(default_module if m_path == "" else m_path)

        _callable = getattr(module, cls)
        kwargs = {}
    else:
        raise NotImplementedError(f"This type of input is not supported")
    return _callable, kwargs


get_cls_kwargs = get_callable_kwargs  # NOTE: this is for compatibility for the previous version


def init_instance_by_config(
    config: InstConf,
    default_module=None,
    accept_types: Union[type, Tuple[type]] = (),
    try_kwargs: Dict = {},
    **kwargs,
) -> Any:
    """
    get initialized instance with config

    Parameters
    ----------

View on GitHub (pinned to 79633dd950)

Solutions

  1. Pass a dict: {'class': 'ClassName', 'module_path': 'pkg.module', 'kwargs': {...}}.
  2. Or pass a fully qualified string 'pkg.module.ClassName'.
  3. Or pass the class object itself (e.g. MyHandlerClass) when it is already imported; make sure JSON configs are json.load()-ed before use.

Example fix

// before
inst = init_instance_by_config(['qlib.contrib.data.handler.Alpha158'])  # NotImplementedError

// after
inst = init_instance_by_config({'class': 'Alpha158', 'module_path': 'qlib.contrib.data.handler'})
Defensive patterns

Strategy: type-guard

Validate before calling

from collections.abc import Mapping
ok = isinstance(conf, (str, type)) or (isinstance(conf, Mapping) and 'class' in conf)
assert ok, f'bad instance config: {conf!r}'

Type guard

def is_valid_inst_conf(conf) -> bool:
    return isinstance(conf, str) or isinstance(conf, type) or (isinstance(conf, Mapping) and 'class' in conf)

Try / catch

try:
    inst = init_instance_by_config(conf)
except NotImplementedError:
    raise ValueError(f'config must be str/dict/class, got {type(conf).__name__}') from None

Prevention

When it happens

Trigger: init_instance_by_config(['MyClass']) (list instead of dict), init_instance_by_config(123), or passing a Mapping-like object that is not an instance of collections.abc.Mapping (e.g. a JSON string that was never parsed).

Common situations: Workflow YAML where a config block is a list of one config rather than the config itself; config loaded from JSON remaining a str; passing a variable that was expected to be a class but is an instance/None; refactors that wrap configs in extra nesting.

Related errors


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