Skip to content

Commit

Permalink
Make model not found uniform
Browse files Browse the repository at this point in the history
Signed-off-by: Frederik Stoel <67371523+wfstoel@users.noreply.github.com>
  • Loading branch information
wfstoel authored Sep 12, 2023
1 parent deb9eb0 commit 296e1ce
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions openstef/model/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ def load_model(
if not models_df.empty:
latest_run = models_df.iloc[0] # Use .iloc[0] to only get latest run
else:
raise LookupError(
f"Model not found for experiment_name {experiment_name}. First"
" train a model!"
)
raise LookupError("Model not found. First train a model!")
model_uri = self._get_model_uri(latest_run.artifact_uri)
loaded_model = mlflow.sklearn.load_model(model_uri)
loaded_model.age = self._determine_model_age_from_mlflow_run(latest_run)
Expand All @@ -162,11 +159,8 @@ def load_model(
) # Path without file:///
self.logger.info("Model successfully loaded with MLflow")
return loaded_model, model_specs
except (AttributeError, MlflowException, OSError) as e:
raise AttributeError(
f"Model not found for experiment_name {experiment_name}. First train a"
" model!"
) from e
except (AttributeError, MlflowException, OSError) as exception:
raise LookupError("Model not found. First train a model!") from exception

def get_model_age(
self, experiment_name: str, hyperparameter_optimization_only: bool = False
Expand Down

0 comments on commit 296e1ce

Please sign in to comment.