Issue Description
Multiplying with a constant that has a subset of coordinates on a shared dimension behaves differently for Variable vs LinearExpression:
x * subset_da works (produces NaN coefficients)
(1 * x) * subset_da fails with AssertionError
Mathematically these should be equivalent.
Reproducible Example
import pandas as pd
import xarray as xr
import linopy
m = linopy.Model()
x = m.add_variables(coords=[pd.Index(range(5), name="i")])
subset_da = xr.DataArray([10.0, 30.0], dims=["i"], coords={"i": [1, 3]})
# This works
result1 = x * subset_da
print(result1.coeffs.values) # [nan, 10., nan, 30., nan]
# This fails with AssertionError
expr = 1 * x
result2 = expr * subset_da # AssertionError in _multiply_by_constant
Expected Behavior
Both operations should behave consistently. Either:
- Both succeed with same result, or
- Both raise an error indicating misaligned coordinates
Installed Versions
Details
master branch (commit 59f92ae)