{"record":{"id":"4de9b81e9294fad5","repo":"microsoft/qlib","slug":"if-path-is-not-given-the-create-path-function-s","errorCode":null,"errorMessage":"If path is not given, the `create_path` function should be implemented","messagePattern":"If path is not given, the `create_path` function should be implemented","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/utils/objm.py","lineNumber":106,"sourceCode":"        raise NotImplementedError(f\"Please implement the `remove` method\")\n\n\nclass FileManager(ObjManager):\n    \"\"\"\n    Use file system to manage objects\n    \"\"\"\n\n    def __init__(self, path=None):\n        if path is None:\n            self.path = Path(self.create_path())\n        else:\n            self.path = Path(path).resolve()\n\n    def create_path(self) -> str:\n        try:\n            return tempfile.mkdtemp(prefix=str(C[\"file_manager_path\"]) + os.sep)\n        except AttributeError as attribute_e:\n            raise NotImplementedError(\n                f\"If path is not given, the `create_path` function should be implemented\"\n            ) from attribute_e\n\n    def save_obj(self, obj, name):\n        with (self.path / name).open(\"wb\") as f:\n            pickle.dump(obj, f, protocol=C.dump_protocol_version)\n\n    def save_objs(self, obj_name_l):\n        for obj, name in obj_name_l:\n            self.save_obj(obj, name)\n\n    def load_obj(self, name):\n        with (self.path / name).open(\"rb\") as f:\n            return restricted_pickle_load(f)\n\n    def exists(self, name):\n        return (self.path / name).exists()\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/objm.py#L88-L124","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an explicit path: FileManager(path='/tmp/my_objs') — no qlib.init needed.","Or call qlib.init() (even with a minimal conf) before constructing FileManager so C['file_manager_path'] exists.","For a custom manager, override create_path() to return your own directory string."],"exampleFix":"// before\nmgr = FileManager()  # NotImplementedError if qlib.init() never ran\n\n// after\nmgr = FileManager(path='/tmp/my_objs')","handlingStrategy":"validation","validationCode":"import qlib\ntry:\n    _ = qlib.config.C['file_manager_path']\n    mgr = FileManager()\nexcept Exception:\n    mgr = FileManager(path='/tmp/my_objs')  # explicit path avoids config dependency","typeGuard":null,"tryCatchPattern":"try:\n    mgr = FileManager()\nexcept NotImplementedError:\n    mgr = FileManager(path=tempfile.mkdtemp(prefix='objs'))","preventionTips":["Always pass an explicit path to FileManager in scripts, tests and subprocess workers.","Ensure qlib.init() runs before any config-dependent utility is constructed, especially under multiprocessing spawn."],"tags":["qlib","objm","filemanager","initialization","config"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}