Cornerstone-OnDemand/modelkit

Do not raise KeyError and reduce try context in ModelLibrary.get()

Closed this issue · 0 comments

This try/except is quite large and except KeyError.

When a model raises a KeyError exception in _load() the exception is catch and re-raised with the wrong error message.

e.g.

import modelkit

class SomeModel(modelkit.Model):
    CONFIGURATIONS = {"model": {}}

    def _load(self):
        data = {}
        data[0]

    def _predict(self, item):
        return item


library = modelkit.ModelLibrary(
    models=SomeModel,
    settings={"lazy_loading": True},
)

library.get("model")

leads to a strange exception message

KeyError: 'Model model not loaded. (loaded models: model).'

instead of

KeyError: 0