microsoft/qlib · error · OSError

Invalid mount path

Error message

Invalid mount path

What it means

MemCache.__getitem__ (qlib/data/cache.py:173) is a dispatcher: the key must be one of three single-letter strings — 'c' (calendar cache), 'i' (instrument cache), 'f' (feature cache). Any other key raises KeyError('Unknown memcache unit'). Code throughout qlib accesses the shared cache H as H["c"], H["i"], H["f"], so this error means a caller used an undocumented key.

Source

Thrown at qlib/__init__.py:123

        sys_type = platform.system()
        if "windows" in sys_type.lower():
            # system: window
            try:
                subprocess.run(
                    ["mount", "-o", "anon", provider_uri, mount_path],
                    capture_output=True,
                    text=True,
                    check=True,
                )
                LOG.info("Mount finished.")
            except subprocess.CalledProcessError as e:
                error_output = (e.stdout or "") + (e.stderr or "")
                if e.returncode == 85:
                    LOG.warning(f"{provider_uri} already mounted at {mount_path}")
                elif e.returncode == 53:
                    raise OSError("Network path not found") from e
                elif "error" in error_output.lower() or "错误" in error_output:
                    raise OSError("Invalid mount path") from e
                else:
                    raise OSError(f"Unknown mount error: {error_output.strip()}") from e
        else:
            # system: linux/Unix/Mac
            # check mount
            _remote_uri = provider_uri[:-1] if provider_uri.endswith("/") else provider_uri
            # `mount a /b/c` is different from `mount a /b/c/`. So we convert it into string to make sure handling it accurately
            mount_path = str(mount_path)
            _mount_path = mount_path[:-1] if mount_path.endswith("/") else mount_path
            _check_level_num = 2
            _is_mount = False
            while _check_level_num:
                with subprocess.Popen(
                    ["mount"],
                    text=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                ) as shell_r:

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use one of the documented units: 'c' for calendar, 'i' for instrument, 'f' for feature series
  2. If you need custom cached data, use your own dict/MemCache instance rather than overloading qlib's H
  3. Check the variable holding the key is not None or '' from an upstream bug

Example fix

# before
cal_cache = H["calendar"]

# after
from qlib.data.cache import H
cal_cache = H["c"]
Defensive patterns

Strategy: type-guard

Validate before calling

VALID_UNITS = {"c", "i", "f"}

def get_cache_unit(key: str):
    assert key in VALID_UNITS, f"memcache unit must be one of {VALID_UNITS}, got {key!r}"
    return H[key]

Type guard

def is_memcache_unit(key: str) -> bool:
    return key in ("c", "i", "f")

Try / catch

try:
    unit = H[key]
except KeyError as e:
    if "Unknown memcache unit" in str(e):
        # fall back to explicit unit selection
        unit = {"calendar": "c", "instrument": "i", "feature": "f"}[key]
    else:
        raise

Prevention

When it happens

Trigger: Calling H[<key>] on the qlib mem-cache object qlib.data.cache.H with a key other than 'c', 'i', 'f' — e.g. H["calendar"] or a variable that accidentally holds None/empty string; usually only hit by code touching qlib internals directly.

Common situations: Custom cache-aware providers or monkey-patches that assume a dict-like arbitrary-key cache; refactoring code where a key constant was renamed.

Related errors


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