From 76d6a8029a381dc36a1eb6a1703a5ecdb24d797a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoshiki=20V=C3=A1zquez=20Baeza?= Date: Wed, 25 May 2022 10:11:35 -0700 Subject: [PATCH] ENH: Fix warning and improve Exception formatting --- codacore/model.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/codacore/model.py b/codacore/model.py index df52b03..47c2088 100644 --- a/codacore/model.py +++ b/codacore/model.py @@ -1,5 +1,6 @@ import numpy as np +import warnings from time import time import statsmodels.api as sm from sklearn.metrics import log_loss @@ -51,7 +52,7 @@ def set_type(self, type): elif type in ['amalgamations', 'amalgam', 'A', 'SLR']: return 'A' else: - raise ValueError("Invalid 'type' argument given", type) + raise ValueError("Invalid 'type' argument given: '%s'" % type) def set_cv_params(self, cv_params): """Overrides the defaults with any user-specified params""" @@ -288,7 +289,8 @@ def gradient_descent(lr, epochs): def set_threshold_cv(self, x, y, current_estimate): if np.any(np.abs(self.soft_assignment) > 0.999999): - Warning("Large weights encountered in gradient descent; vanishing gradients likely.") + warnings.warn("Large weights encountered in gradient descent; " + "vanishing gradients likely.", Warning) candidate_thresholds = -np.sort(-np.abs(self.soft_assignment)) num_thresholds = self.cv_params['num_thresholds'] @@ -357,7 +359,7 @@ def get_logratio(self, x): epsilon = self.opt_params['epsilon_a'] logratio = np.log(positive_part + epsilon) - np.log(negative_part + epsilon) else: - raise ValueError("Unknown type given:", self.type) + raise ValueError("Unknown type given: '%s'" % self.type) return logratio