test: make assert_linequal ignore dimension order#801
Open
FBumann wants to merge 1 commit into
Open
Conversation
linopy expressions inherit xarray's broadcasting, whose dimension order follows operand order: ``x + y`` yields ``(x_dim, y_dim)`` while ``y + x`` yields ``(y_dim, x_dim)``. That difference carries no mathematical meaning, yet xarray's order-sensitive ``assert_equal`` made the two compare unequal. ``assert_linequal`` already normalizes term order; align dimension order the same way before comparing, matching its "semantically equal" contract. Expressions with genuinely different dimension sets or values still fail. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
Collaborator
Author
|
canceled pypsa-tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I hit some false positives while working on sth else. This fixes them. Making the testing more robust.
Note
The following content was generated by AI.
What this does
linopy expressions are dimension-labelled xarray structures, so they inherit
xarray's broadcast order-sensitivity:
x + yproduces dims(x_dim, y_dim)while
y + xproduces(y_dim, x_dim). That difference is not mathematicallymeaningful, but xarray's
assert_equalis order-sensitive, soassert_linequal(x + y, y + x)failed.assert_linequalalready normalizes term order before comparing (itsdocstring promises "semantically equal"). This aligns dimension order the
same way: a new
_align_dim_orderhelper transposes the second operand to thefirst's dimension order when they share a dimension set. If the dimension sets
differ, the expressions are genuinely unequal and the comparison is left
untouched so
assert_equalreports the real difference.Notes
linopy/testing.py; addstest/test_testing.py(dim-orderinsensitivity, plus genuinely-different expressions still fail).
test_linear_expression.py+test_quadratic_expression.pypassunchanged (333), i.e. nothing was relying on the order-sensitive behavior.
Reproducer