diff --git a/linopy/variables.py b/linopy/variables.py index 2d17fef8..c97607ae 100644 --- a/linopy/variables.py +++ b/linopy/variables.py @@ -851,6 +851,8 @@ def type(self) -> str: return "Integer Variable" elif self.attrs["binary"]: return "Binary Variable" + elif self.attrs.get("semi_continuous"): + return "Semi-continuous Variable" else: return "Continuous Variable" diff --git a/test/test_variable.py b/test/test_variable.py index b7aa0491..67ed6690 100644 --- a/test/test_variable.py +++ b/test/test_variable.py @@ -54,6 +54,21 @@ def test_variable_inherited_properties(x: linopy.Variable) -> None: assert isinstance(x.ndim, int) +def test_variable_type() -> None: + m = Model() + x = m.add_variables(lower=0, upper=10, name="x") + assert x.type == "Continuous Variable" + + b = m.add_variables(binary=True, name="b") + assert b.type == "Binary Variable" + + i = m.add_variables(lower=0, upper=10, integer=True, name="i") + assert i.type == "Integer Variable" + + sc = m.add_variables(lower=1, upper=10, semi_continuous=True, name="sc") + assert sc.type == "Semi-continuous Variable" + + def test_variable_labels(x: linopy.Variable) -> None: isinstance(x.labels, xr.DataArray)