microsoft/qlib · error · NotImplementedError
Please implement the `exists` method
Error message
Please implement the `exists` method
What it means
exists(name) is the membership-check method of the abstract ObjManager interface (does an object with this name exist?). The base class deliberately raises NotImplementedError so every concrete backend defines its own existence semantics (file present, key present in DB, etc.).
Source
Thrown at qlib/utils/objm.py:66
loaded object
"""
raise NotImplementedError(f"Please implement the `load_obj` method")
def exists(self, name: str) -> bool:
"""
if the object named `name` exists
Parameters
----------
name : str
name of the objecT
Returns
-------
bool:
If the object exists
"""
raise NotImplementedError(f"Please implement the `exists` method")
def list(self) -> list:
"""
list the objects
Returns
-------
list:
the list of returned objects
"""
raise NotImplementedError(f"Please implement the `list` method")
def remove(self, fname=None):
"""remove.
Parameters
----------
fname :View on GitHub (pinned to 79633dd950)
Solutions
- Use FileManager, whose exists() checks the file in its managed directory.
- Implement exists(self, name) -> bool in your subclass (e.g. return (self.path / name).exists() or a backend HEAD request).
- If you cannot modify the class, replace the exists() call with a try/except around load_obj catching FileNotFoundError/KeyError.
Example fix
// before
if ObjManager().exists('model_v1'): # NotImplementedError
obj = mgr.load_obj('model_v1')
// after
if FileManager(path='./objs').exists('model_v1'):
obj = mgr.load_obj('model_v1') Defensive patterns
Strategy: try-catch
Validate before calling
from qlib.utils.objm import ObjManager
if type(mgr).exists is ObjManager.exists:
raise RuntimeError('manager does not implement exists(); fix subclass') Type guard
def supports_exists(mgr) -> bool:
return type(mgr).exists is not ObjManager.exists Try / catch
try:
present = mgr.exists(name)
except NotImplementedError:
try:
mgr.load_obj(name)
present = True
except (FileNotFoundError, KeyError):
present = False Prevention
- Implement exists() as a cheap backend check in custom managers; never leave it abstract.
- Cache name sets at save time if the backend cannot enumerate cheaply.
When it happens
Trigger: ObjManager().exists('name'), or a custom subclass missing an exists override while application code calls manager.exists(name) before load_obj to avoid load errors.
Common situations: Cache-invalidation logic (`if not mgr.exists(name): save(...)`) written against a custom manager; upgrading qlib versions where exists became expected on all managers; test doubles that skip rarely-used methods.
Related errors
- Please implement `save_obj`
- Please implement the `save_objs` method
- Please implement the `load_obj` method
- Please implement the `list` method
- Please implement the `remove` method
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/cad04fee4a595d84.
Report an issue: GitHub.