microsoft/qlib · error · TypeError

provider_uri does not support {type(provider_uri)}

Error message

provider_uri does not support {type(provider_uri)}

What it means

The same format_provider_uri normalizer in qlib/config.py only accepts str, pathlib.Path, or a dict mapping frequency to uri/path. Any other Python type (int, list, tuple, None-like objects other than None itself) raises TypeError, telling you exactly which type was rejected.

Source

Thrown at qlib/config.py:369

        def __init__(self, provider_uri: Union[str, Path, dict], mount_path: Union[str, Path, dict]):
            """
            The relation of `provider_uri` and `mount_path`
            - `mount_path` is used only if provider_uri is an NFS path
            - otherwise, provider_uri will be used for accessing data
            """
            self.provider_uri = provider_uri
            self.mount_path = mount_path

        @staticmethod
        def format_provider_uri(provider_uri: Union[str, dict, Path]) -> dict:
            if provider_uri is None:
                raise ValueError("provider_uri cannot be None")
            if isinstance(provider_uri, (str, dict, Path)):
                if not isinstance(provider_uri, dict):
                    provider_uri = {QlibConfig.DEFAULT_FREQ: provider_uri}
            else:
                raise TypeError(f"provider_uri does not support {type(provider_uri)}")
            for freq, _uri in provider_uri.items():
                if QlibConfig.DataPathManager.get_uri_type(_uri) == QlibConfig.LOCAL_URI:
                    provider_uri[freq] = str(Path(_uri).expanduser().resolve())
            return provider_uri

        @staticmethod
        def get_uri_type(uri: Union[str, Path]):
            uri = uri if isinstance(uri, str) else str(uri.expanduser().resolve())
            is_win = re.match("^[a-zA-Z]:.*", uri) is not None  # such as 'C:\\data', 'D:'
            # such as 'host:/data/'   (User may define short hostname by themselves or use localhost)
            is_nfs_or_win = re.match("^[^/]+:.+", uri) is not None

            if is_nfs_or_win and not is_win:
                return QlibConfig.NFS_URI
            else:
                return QlibConfig.LOCAL_URI

        def get_data_uri(self, freq: Optional[Union[str, Freq]] = None) -> Path:

View on GitHub (pinned to 79633dd950)

Solutions

  1. Pass provider_uri as a string path, a pathlib.Path, or a dict {'freq': 'path'}.
  2. In YAML, write provider_uri as a plain quoted string: provider_uri: ~/.qlib/qlib_data/cn_data.
  3. Coerce unknown objects before init: provider_uri = str(provider_uri) when it came from a dynamic config source.

Example fix

# before
qlib.init(provider_uri=['~/.qlib/day', '~/.qlib/min'])  # list -> TypeError
# after
qlib.init(provider_uri={'day': '~/.qlib/day', '1min': '~/.qlib/min'})  # dict is supported
Defensive patterns

Strategy: type-guard

Validate before calling

from pathlib import Path
assert isinstance(provider_uri, (str, Path, dict)), f'provider_uri must be str/Path/dict, got {type(provider_uri)}'

Type guard

from pathlib import Path

def is_supported_uri_type(u) -> bool:
    return isinstance(u, (str, Path, dict))

Prevention

When it happens

Trigger: Passing provider_uri as a list of paths, an int/enum, or an object returned by a config loader (e.g. a ruamel/scalar tagged object) to qlib.init; also passing a dict whose values are not str/Path.

Common situations: YAML configs where provider_uri is written as a YAML list or the value is quoted incorrectly so it parses as a non-string scalar; programmatic configs that pass os.environ-like objects or dataclasses.

Related errors


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