fix(variables): Variable.where works with solution attached#790
Merged
Conversation
Variable.where passed a fill dict covering only labels/lower/upper to Dataset.where, which requires an exact match against the dataset's data variables. After solve() or fix() the variable carries extra columns (solution, stashed bounds), so where() raised a ValueError. Augment the fill dict to cover all present data variables, defaulting extras to NaN.
Merging this PR will not alter performance
Comparing Footnotes
|
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.
Note
This PR's description and code changes were generated with AI assistance (Claude Code) and reviewed by a human.
Changes proposed in this Pull Request
Variable.whereraisedValueError: exact match required for all data variable namesas soon as a solution was attached to the model (afterModel.solve) or the variable was fixed.Cause:
Variable.wherepasses a fill dict covering onlylabels/lower/uppertoDataset.where, which requires the fill keys to exactly match the dataset's data variables. After solving (orfix()), the variable's data gains extra columns (solution,_stashed_lower,_stashed_upper), so the match fails.Fix: Augment the fill dict to cover every data variable present, defaulting extras to
NaN. The explicitlabels=-1/lower=upper=NaNentries still override; only auxiliary columns pick up theNaNdefault.This routes through
Variable.fillnatoo, since it delegates towhere. Audited the related methods —ffill/bfill(Dataset.where(cond)+Dataset.fillna(dict)) andshift(Dataset.shift(fill_value=dict)) already tolerate extra data variables, andLinearExpression/QuadraticExpression/Constraintare unaffected (they don't storesolution/dual).Added a regression test
test_variable_where_with_solutionand a release note.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.