Repository navigation
Conversation
`num2bool` fell back to `Piecewise((True, x != 0.0), (False, True))`, where `x != 0.0` is Python's structural inequality, so any non-constant operand of `&&`, `||`, `!` or a `piecewise` condition was treated as `true`. Return `Ne(x, 0)` instead. Also convert symbols (which are sympy `Boolean`s as well) and Boolean-valued `Piecewise` operands. Fixes PEtab-dev#581. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`bool2num` only converted `true` and `false`, so e.g. `1 + (x > 0)` failed with `TypeError: Relational cannot be used in Add`. Convert other Booleans `b` to `Piecewise((1.0, b), (0.0, True))`, and convert `piecewise` values, since `piecewise` is float-valued. Since `sympify_petab` applies `bool2num` to the final result, a top-level Boolean expression like `x > 0` is now returned as a `Piecewise` instead of a relational, consistent with `true` -> `1.0`. Add printing of `ITE`, which sympy may create in `Piecewise` conditions. Fixes PEtab-dev#582. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #584 +/- ##
==========================================
+ Coverage 79.48% 79.51% +0.02%
==========================================
Files 70 70
Lines 8278 8280 +2
Branches 1498 1498
==========================================
+ Hits 6580 6584 +4
+ Misses 1207 1206 -1
+ Partials 491 490 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Fix non-constant Booleans in numeric context, e.g.
1 + (x > 0), which failed withTypeError: Relational cannot be used in Add. Per the PEtab v2 spec,trueis converted to1.0andfalseto0.0.bool2numnow converts non-constant BooleansbtoPiecewise((1.0, b), (0.0, True)).piecewisevalues are converted as well, sincepiecewiseis float-valued.petab_math_strcan now printITE, which sympy may create inPiecewiseconditions (e.g. for(x > 0) == (y > 2)).Behaviour change:
sympify_petabapplies this conversion to the final result as well, so a top-level Boolean expression likex > 0is now returned asPiecewise((1.0, x > 0), (0.0, True))instead of a relational. This is consistent with the existing handling oftrue->1.0and with the PEtab test suite.Builds on #583; only the last commit belongs to this PR. It also removes the
Piecewisehandling that #583 added tonum2bool, which is no longer needed, and updates the expected values in #583's tests to floats.Fixes #582.
🤖 Generated with Claude Code