Treat NaN as absent in v1 arithmetic#627
Draft
FBumann wants to merge 6 commits intoharmonize-linopy-operations-mixedfrom
Draft
Treat NaN as absent in v1 arithmetic#627FBumann wants to merge 6 commits intoharmonize-linopy-operations-mixedfrom
FBumann wants to merge 6 commits intoharmonize-linopy-operations-mixedfrom
Conversation
NaN in multiplicative/divisive constants now masks the term (makes it absent) rather than raising. NaN in additive constants is treated as 0 (additive identity). NaN in constraint RHS skips the constraint. This simplifies the API — users no longer need fillna() before every operation with incomplete data. Update arithmetic-convention, missing-data, and new mixed-coordinate-arithmetic notebooks to reflect the new semantics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Variable.to_linexpr() now treats NaN coefficients as absent in v1, consistent with Expression * NaN (was silently filling with 0) - Restore ValueError for NaN in constraint RHS — silently skipping constraints is too dangerous at this API boundary - Update notebooks to reflect both changes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
10 tasks
NaN already in the data (user-intentional) still masks silently. But NaN introduced by coordinate alignment (join="left"/"outer") now raises ValueError, requiring explicit fill_value=0 or fill_value=1. This catches the footgun where a partial scaling factor (e.g., rate covering only some techs) silently masks terms instead of preserving them with the identity element. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
ValueErrorValueError— silently skipping constraints is too dangerousVariable.to_linexpr(nan_coeff)now correctly produces absent slots in v1 (was inconsistently filling with 0)mixed-coordinate-arithmetic.ipynbnotebook documenting patterns for combining variables with different coordinate subsets (from PR #591 feedback)Motivation
Addresses @brynpickering's feedback in #591: the
fillna(0)ceremony before every multiplication with incomplete cost data was verbose and error-prone. With NaN-as-mask, the pre-align pattern becomes clean:NaN behavior summary (v1)
expr + nanexpr * nanexpr / nanexpr <= nanValueError(use.sel()/mask=)Test plan
arithmetic-convention,missing-data,mixed-coordinate-arithmetic🤖 Generated with Claude Code