Skip to content

Make LinearExpression multiplication with constant containing subset of dimensions consistent with Variable behaviour - #571

Closed
RobbieKiwi wants to merge 1 commit into
PyPSA:masterfrom
RobbieKiwi:feature/consistent-multiplication
Closed

Make LinearExpression multiplication with constant containing subset of dimensions consistent with Variable behaviour#571
RobbieKiwi wants to merge 1 commit into
PyPSA:masterfrom
RobbieKiwi:feature/consistent-multiplication

Conversation

@RobbieKiwi

@RobbieKiwiRobbieKiwi commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Closes#569#570

Changes proposed in this Pull Request

Now LinearExpression behaves the same way as Variable when multiplying with a constant containing a susbet of dimensions. Still it is not consistent with addition.

ActionCoordsMissing coord behaviour
AdditionSame coordsadd 0
Variable MultiplicationSame coordsnan
Expression MultiplicationSame coordsnan

For addition, when a coord is mising we just add 0 (I.e do nothing at that coord)
Perhaps the equivalent for multiplication would be to multiply by 1 (also do nothing) rather than fill with nan?

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@RobbieKiwi

Copy link
Copy Markdown
ContributorAuthor

@FabianHofmann I like your PR #572 better so I will close this one

FBumann added a commit that referenced this pull request Mar 14, 2026
Documents 5 categories of legacy issues with paired legacy/v1 tests:
1. Positional alignment (#586, #550): same-shape operands with different
labels silently paired by position, producing wrong results
2. Subset constant associativity (#572): left-join drops coordinates,
making (a+c)+b != a+(c+b)
3. User NaN swallowed (#620): NaN in user data silently filled with
inconsistent neutral elements (0 for add/mul, 1 for div)
4. Variable vs Expression inconsistency (#569, #571): x*c and (1*x)*c
previously gave different results
5. Absent slot propagation (#620): legacy can't distinguish absent
variables from zero, fillna() is a no-op
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent multiplication behavior: Variable vs LinearExpression with subset coordinates

1 participant

@RobbieKiwi