Skip to content

Commit 16b609f

Browse files
committed
fix: The shape property is now consistent between LinearExpression and QuadraticExpression - both exclude internal dimensions (_term for linear, _term and
_factor for quadratic)
1 parent ccf9db1 commit 16b609f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

linopy/expressions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,10 +1069,9 @@ def nterm(self) -> int:
10691069
@property
10701070
def shape(self) -> tuple[int, ...]:
10711071
"""
1072-
Get the total shape of the linear expression.
1072+
Get the shape of the expression (excluding term dimension).
10731073
"""
1074-
assert self.vars.shape == self.coeffs.shape
1075-
return self.vars.shape
1074+
return tuple(v for k, v in self.sizes.items() if k != TERM_DIM)
10761075

10771076
@property
10781077
def size(self) -> int:

test/test_linear_expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_linear_expression_with_constant_multiplication(
317317

318318
obs = expr * pd.Series([1, 2, 3], index=pd.RangeIndex(3, name="new_dim"))
319319
assert isinstance(obs, LinearExpression)
320-
assert obs.shape == (2, 3, 1)
320+
assert obs.shape == (2, 3)
321321

322322

323323
def test_linear_expression_multi_indexed(u: Variable) -> None:

0 commit comments

Comments
 (0)