From 9014b29f7b471722250ae4723aa89197d925b006 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:12:17 +0100 Subject: [PATCH] fix: Include semi-continuous in Variable.type property Variable.type only checked integer and binary attributes, falling through to "Continuous Variable" for semi-continuous variables. Co-Authored-By: Claude Opus 4.6 (1M context) --- linopy/variables.py | 2 ++ test/test_variable.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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)