microsoft/qlib · error · NotImplementedError

If path is not given, the `create_path` function should be i

Error message

If path is not given, the `create_path` function should be implemented

What it means

FileManager with no `path` argument derives its storage directory via create_path(), which makes a temp dir prefixed with qlib's global config value C['file_manager_path']. That key only exists after qlib.init() has been called; when it is missing, the AttributeError from the config lookup is chained into NotImplementedError telling you to either give a path or implement create_path.

Source

Thrown at qlib/utils/objm.py:106

        raise NotImplementedError(f"Please implement the `remove` method")


class FileManager(ObjManager):
    """
    Use file system to manage objects
    """

    def __init__(self, path=None):
        if path is None:
            self.path = Path(self.create_path())
        else:
            self.path = Path(path).resolve()

    def create_path(self) -> str:
        try:
            return tempfile.mkdtemp(prefix=str(C["file_manager_path"]) + os.sep)
        except AttributeError as attribute_e:
            raise NotImplementedError(
                f"If path is not given, the `create_path` function should be implemented"
            ) from attribute_e

    def save_obj(self, obj, name):
        with (self.path / name).open("wb") as f:
            pickle.dump(obj, f, protocol=C.dump_protocol_version)

    def save_objs(self, obj_name_l):
        for obj, name in obj_name_l:
            self.save_obj(obj, name)

    def load_obj(self, name):
        with (self.path / name).open("rb") as f:
            return restricted_pickle_load(f)

    def exists(self, name):
        return (self.path / name).exists()

View on GitHub (pinned to 79633dd950)

Solutions

  1. Pass an explicit path: FileManager(path='/tmp/my_objs') — no qlib.init needed.
  2. Or call qlib.init() (even with a minimal conf) before constructing FileManager so C['file_manager_path'] exists.
  3. For a custom manager, override create_path() to return your own directory string.

Example fix

// before
mgr = FileManager()  # NotImplementedError if qlib.init() never ran

// after
mgr = FileManager(path='/tmp/my_objs')
Defensive patterns

Strategy: validation

Validate before calling

import qlib
try:
    _ = qlib.config.C['file_manager_path']
    mgr = FileManager()
except Exception:
    mgr = FileManager(path='/tmp/my_objs')  # explicit path avoids config dependency

Try / catch

try:
    mgr = FileManager()
except NotImplementedError:
    mgr = FileManager(path=tempfile.mkdtemp(prefix='objs'))

Prevention

When it happens

Trigger: FileManager() (no path) executed before any qlib.init(...) call, or in a fresh subprocess/script that imports qlib.utils but never initializes the global config C.

Common situations: Utility scripts and unit tests that use FileManager for scratch storage without bootstrapping qlib; multiprocessing workers (spawned processes re-import without init); running a small snippet in a notebook before initializing qlib in another cell.

Related errors


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