diff --git a/ema_workbench/analysis/cart.py b/ema_workbench/analysis/cart.py index 54735d190..59dfc1340 100644 --- a/ema_workbench/analysis/cart.py +++ b/ema_workbench/analysis/cart.py @@ -142,7 +142,8 @@ def boxes(self): # based on # http://stackoverflow.com/questions/20224526/how-to-extract-the- # decision-rules-from-scikit-learn-decision-tree - assert self.clf + if not self.clf: + raise AssertionError left = self.clf.tree_.children_left right = self.clf.tree_.children_right diff --git a/ema_workbench/analysis/plotting_util.py b/ema_workbench/analysis/plotting_util.py index 7e8cf391d..8b401e1c3 100644 --- a/ema_workbench/analysis/plotting_util.py +++ b/ema_workbench/analysis/plotting_util.py @@ -660,8 +660,10 @@ def make_continuous_grouping_specifiers(array, nr_of_groups=5): maximum = np.max(array) step = (maximum - minimum) / nr_of_groups a = [(minimum + step * x, minimum + step * (x + 1)) for x in range(nr_of_groups)] - assert a[0][0] == minimum - assert a[-1][1] == maximum + if a[0][0] != minimum: + raise AssertionError + if a[-1][1] != maximum: + raise AssertionError return a diff --git a/ema_workbench/analysis/prim_util.py b/ema_workbench/analysis/prim_util.py index 8631e2935..f69f17f24 100644 --- a/ema_workbench/analysis/prim_util.py +++ b/ema_workbench/analysis/prim_util.py @@ -42,8 +42,10 @@ def get_quantile(data, quantile): the desired quantile """ - assert quantile > 0 - assert quantile < 1 + if quantile <= 0: + raise AssertionError + if quantile >= 1: + raise AssertionError data = np.sort(data) diff --git a/ema_workbench/analysis/scenario_discovery_util.py b/ema_workbench/analysis/scenario_discovery_util.py index 7ea15048c..645909715 100644 --- a/ema_workbench/analysis/scenario_discovery_util.py +++ b/ema_workbench/analysis/scenario_discovery_util.py @@ -278,7 +278,8 @@ def _setup(results, classify, incl_unc=[]): else: raise TypeError("unknown type for classify") - assert y.ndim == 1 + if y.ndim != 1: + raise AssertionError return x, y, mode diff --git a/ema_workbench/connectors/simio_connector.py b/ema_workbench/connectors/simio_connector.py index b1ed267b5..028c291df 100644 --- a/ema_workbench/connectors/simio_connector.py +++ b/ema_workbench/connectors/simio_connector.py @@ -89,7 +89,8 @@ def __init__( """ super().__init__(name, wd=wd, model_file=model_file) - assert main_model != None + if main_model == None: + raise AssertionError self.main_model_name = main_model self.output = {} self.n_replications = n_replications diff --git a/ema_workbench/em_framework/evaluators.py b/ema_workbench/em_framework/evaluators.py index b4513082a..52397d88e 100644 --- a/ema_workbench/em_framework/evaluators.py +++ b/ema_workbench/em_framework/evaluators.py @@ -768,9 +768,12 @@ def robust_optimize( """ for rf in robustness_functions: - assert isinstance(rf, ScalarOutcome) - assert rf.kind != AbstractOutcome.INFO - assert rf.function is not None + if not isinstance(rf, ScalarOutcome): + raise AssertionError + if rf.kind == AbstractOutcome.INFO: + raise AssertionError + if rf.function is None: + raise AssertionError problem = to_robust_problem( model, diff --git a/ema_workbench/em_framework/optimization.py b/ema_workbench/em_framework/optimization.py index cd750fdc0..3d2d638fc 100644 --- a/ema_workbench/em_framework/optimization.py +++ b/ema_workbench/em_framework/optimization.py @@ -115,14 +115,18 @@ def __init__( super().__init__(len(parameters), len(outcome_names), nconstrs=len(constraints)) # assert len(parameters) == len(parameter_names) - assert searchover in ("levers", "uncertainties", "robust") + if searchover not in ("levers", "uncertainties", "robust"): + raise AssertionError if searchover == "levers": - assert not reference or isinstance(reference, Scenario) + if not (not reference or isinstance(reference, Scenario)): + raise AssertionError elif searchover == "uncertainties": - assert not reference or isinstance(reference, Policy) + if not (not reference or isinstance(reference, Policy)): + raise AssertionError else: - assert not reference + if reference: + raise AssertionError self.searchover = searchover self.parameters = parameters @@ -140,7 +144,8 @@ def __init__( self, parameters, outcome_names, scenarios, robustness_functions, constraints ): super().__init__("robust", parameters, outcome_names, constraints) - assert len(robustness_functions) == len(outcome_names) + if len(robustness_functions) != len(outcome_names): + raise AssertionError self.scenarios = scenarios self.robustness_functions = robustness_functions @@ -604,7 +609,8 @@ def __init__( self.logging_freq = logging_freq for metric in metrics: - assert isinstance(metric, AbstractConvergenceMetric) + if not isinstance(metric, AbstractConvergenceMetric): + raise AssertionError metric.reset() def __call__( diff --git a/ema_workbench/em_framework/outcomes.py b/ema_workbench/em_framework/outcomes.py index 67ca25869..a4d083175 100644 --- a/ema_workbench/em_framework/outcomes.py +++ b/ema_workbench/em_framework/outcomes.py @@ -549,7 +549,8 @@ class Constraint(ScalarOutcome): """ def __init__(self, name, parameter_names=None, outcome_names=None, function=None): - assert callable(function) + if not callable(function): + raise AssertionError if not parameter_names: parameter_names = [] elif isinstance(parameter_names, str): @@ -574,7 +575,8 @@ def __init__(self, name, parameter_names=None, outcome_names=None, function=None def process(self, values): value = super().process(values) - assert value >= 0 + if value < 0: + raise AssertionError return value diff --git a/ema_workbench/em_framework/parameters.py b/ema_workbench/em_framework/parameters.py index 9232647c2..9840adc50 100644 --- a/ema_workbench/em_framework/parameters.py +++ b/ema_workbench/em_framework/parameters.py @@ -159,9 +159,10 @@ def from_dist(cls, name, dist, **kwargs): **kwargs : valid keyword arguments for Parameter instance """ - assert isinstance( + if not isinstance( dist, sp.stats._distn_infrastructure.rv_frozen - ) # @UndefinedVariable + ): + raise AssertionError self = cls.__new__(cls) self.dist = dist self.name = name