linopy.variables.Variable.to_linexpr

linopy.variables.Variable.to_linexpr#

Variable.to_linexpr(coefficient=1, *, _warn_absence=True)#

Create a linear expression from the variables.

Parameters:

coefficient (array-like, optional) – Coefficient for the linear expression. This can be a numeric value, numpy array, pandas series/dataframe or a DataArray. Default is 1.

Returns:

linopy.LinearExpression – Linear expression with the variables and coefficients.

Notes

The §8 shared-dim check runs on the raw coefficient, before the broadcast aligns it away — the reindex below only fills absence and broadcasts non-shared dims. A NaN coefficient is user data, so it raises under v1 (§5). Under v1 the expression carries the variable’s absence as NaN so that §6 propagates it through downstream arithmetic; legacy contributes 0 there instead and warns, that being the most common legacy↔v1 divergence and one no other warn site catches.