fix(v1): make Variable.fillna(scalar) resolve absence under both conventions (#847, #848)#851
Merged
FBumann merged 2 commits intoJul 20, 2026
Conversation
…entions (#847, #848) Variable.fillna(<scalar>) is the documented resolution for absent slots (from shift/where/reindex/mask), but under legacy it misbehaved two ways: - #847: it warned. fillna internally calls to_linexpr(), whose legacy path emits the masked-variable LinopySemanticsWarning — even though fillna is itself the resolution that warning points to. So the documented fix couldn't be written warning-free on both conventions. - #848: it silently dropped the fill value. Legacy to_linexpr marks absent const as 0 (not NaN), so the subsequent LinearExpression.fillna had nothing to fill; fillna(5) left 0 at absent slots while v1 put 5. The v1 path already behaved correctly, so this is a pure legacy workaround (marked LEGACY: remove at 1.0): keep the clean one-liner under v1, and under legacy place the value at the -1 labels directly and skip the absence warning. Result: `var.shift(1).fillna(v)` is now a single form, identical under both conventions (same vars/const; only the immaterial phantom coeff differs), so downstream migrating to v1 no longer has to version-gate the expression. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Document why var.to_linexpr().fillna(v) is a no-op under legacy (absence is already materialised as const=0, so there is no NaN to fill) and point at Variable.fillna as the cross-convention resolution. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FBumann
marked this pull request as ready for review
July 20, 2026 07:44
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.
Closes #847, closes #848. Stacked on
feat/arithmetic-convention(#717).Note
The following content was generated by AI.
Problem
Variable.fillna(<scalar>)is the documented resolution for absent slots (fromshift/where/reindex/mask), but under legacy it misbehaved two ways, so there was no single form valid under both conventions:fillnacallsto_linexpr(), whose legacy path emits the masked-variableLinopySemanticsWarning, even thoughfillnais the resolution that warning points to.to_linexprmarks absentconstas0(notNaN), so the subsequentLinearExpression.fillnahad nothing to fill:fillna(5)left0at absent slots while v1 put5.Fix
The v1 path already behaved correctly, so this is a pure legacy workaround (marked
LEGACY: remove at 1.0):self.to_linexpr().fillna(fill_value).-1labels directly and skip the absence warning (via a private_warn_absenceflag onto_linexpr).var.shift(1).fillna(v)is now a single form, identical under both conventions — samevars/const; only the immaterial phantom coefficient atvars == -1slots differs (dropped at solve time).Note: the raw two-step
var.to_linexpr().fillna(v)remains a legacy no-op — that low-level path has already overwritten absence with0.Variable.fillnais correct because it still holds the-1labels.Cross-release (0.8.0) is intentionally out of scope: downstream requires the v1 release rather than a 0.8.x backport (a naive backport would be silently wrong for non-zero fills).
Tests
test_legacy_variable_fillna_numeric_fills_like_v1— legacy fill now lands (was pinned as a no-op).test_legacy_variable_fillna_does_not_warn— the documented resolution no longer warns.