microsoft/qlib · critical · ValueError

account must be in (int, float, dict)

Error message

account must be in (int, float, dict)

What it means

DatasetCache._dataset_uri (qlib/data/cache.py:444) is the abstract method that returns the URI of the dataset cache file, with special semantics: disk_cache=1 returns the cache-file URI for the client to load; disk_cache=0 means the server checks/generates expression caches and the client loads data itself. The base class raises NotImplementedError because URI generation depends entirely on the cache mechanism.

Source

Thrown at qlib/backtest/__init__.py:159

                ]
        information for describing how to creating the account
        For `float`:
            Using Account with only initial cash
        For `dict`:
            key "cash" means initial cash.
            key "stock1" means the information of first stock with amount and price(optional).
            ...
    pos_type: str
        Postion type.
    """
    if isinstance(account, (int, float)):
        init_cash = account
        position_dict = {}
    elif isinstance(account, dict):
        init_cash = account.pop("cash")
        position_dict = account
    else:
        raise ValueError("account must be in (int, float, dict)")

    return Account(
        init_cash=init_cash,
        position_dict=position_dict,
        pos_type=pos_type,
        benchmark_config=(
            {}
            if benchmark is None
            else {
                "benchmark": benchmark,
                "start_time": start_time,
                "end_time": end_time,
            }
        ),
    )


def get_strategy_executor(

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use DiskDatasetCache, which implements _dataset_uri for the standard hash-based file layout
  2. Override _dataset_uri(self, instruments, fields, start_time=None, end_time=None, freq='day', disk_cache=1, inst_processors=[]) in your subclass honoring the disk_cache=0/1 semantics documented in the docstring
  3. If you never need URI serving (pure local use), call D.features with disk_cache=0 to bypass dataset-cache URI resolution

Example fix

# before
D.features(instruments, fields, start, end, disk_cache=1)  # cache lacks _dataset_uri

# after
D.features(instruments, fields, start, end, disk_cache=0)  # bypass dataset cache URI
# or: qlib.init(dataset_cache=DiskDatasetCache)
Defensive patterns

Strategy: validation

Validate before calling

from qlib.data.cache import DatasetCache

assert MyDSCache._dataset_uri is not DatasetCache._dataset_uri, \
    "dataset URI serving requires _dataset_uri"
# or simply avoid the path:
# D.features(..., disk_cache=0)

Try / catch

try:
    uri = cache._dataset_uri(insts, fields, start, end, disk_cache=1)
except NotImplementedError:
    uri = cache._dataset_uri(insts, fields, start, end, disk_cache=0)  # client-side load path

Prevention

When it happens

Trigger: Client/server mode: calling D.features(..., disk_cache=1) or the DatasetProvider.dataset path that needs a downloadable cache URI while the configured DatasetCache subclass does not implement _dataset_uri; also hit in DatasetURICache-style flows where the URI itself is the product.

Common situations: Custom dataset caches implementing _dataset/_uri but missing _dataset_uri; using the abstract DatasetCache directly; client/server qlib deployments where the client requests dataset URIs.

Related errors


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