Skip to content

Commit 1bc3efc

Browse files
FBumannclaude
andauthored
fix: Include semi-continuous in Variable.type property (#635)
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) <noreply@anthropic.com>
1 parent f8dcfea commit 1bc3efc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

linopy/variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ def type(self) -> str:
851851
return "Integer Variable"
852852
elif self.attrs["binary"]:
853853
return "Binary Variable"
854+
elif self.attrs.get("semi_continuous"):
855+
return "Semi-continuous Variable"
854856
else:
855857
return "Continuous Variable"
856858

test/test_variable.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def test_variable_inherited_properties(x: linopy.Variable) -> None:
5454
assert isinstance(x.ndim, int)
5555

5656

57+
def test_variable_type() -> None:
58+
m = Model()
59+
x = m.add_variables(lower=0, upper=10, name="x")
60+
assert x.type == "Continuous Variable"
61+
62+
b = m.add_variables(binary=True, name="b")
63+
assert b.type == "Binary Variable"
64+
65+
i = m.add_variables(lower=0, upper=10, integer=True, name="i")
66+
assert i.type == "Integer Variable"
67+
68+
sc = m.add_variables(lower=1, upper=10, semi_continuous=True, name="sc")
69+
assert sc.type == "Semi-continuous Variable"
70+
71+
5772
def test_variable_labels(x: linopy.Variable) -> None:
5873
isinstance(x.labels, xr.DataArray)
5974

0 commit comments

Comments
 (0)