diff --git a/pypsa/optimization/abstract.py b/pypsa/optimization/abstract.py index 50ae55d86..a1ec4f76a 100644 --- a/pypsa/optimization/abstract.py +++ b/pypsa/optimization/abstract.py @@ -381,13 +381,20 @@ def optimize_mga( objective + fixed_cost <= (1 + slack) * optimal_cost, name="budget" ) - # parse optimization sense - if sense.startswith("min") or sense > 0: - sense = 1 - elif sense.startswith("max") or sense < 0: - sense = -1 + if isinstance(sense, str): + if sense.startswith("min"): + sense = 1 + elif sense.startswith("max"): + sense = -1 + else: + raise ValueError(f"Could not parse optimization sense {sense}") else: - raise ValueError(f"Could not parse optimization sense {sense}") + if sense > 0: + sense = 1 + elif sense < 0: + sense = -1 + else: + raise ValueError(f"Could not parse optimization sense {sense}") # build alternate objective objective = []