Skip to content

Reject NaN and complex infinity in PEtab math output - #613

Open
ChenYueqi2024 wants to merge 2 commits into
PEtab-dev:mainfrom
ChenYueqi2024:fix/reject-invalid-math-549
Open

ChenYueqi2024 wants to merge 2 commits into
PEtab-dev:mainfrom
ChenYueqi2024:fix/reject-invalid-math-549

Conversation

@ChenYueqi2024

Copy link
Copy Markdown

Fixes #549.

petab_math_str(sp.nan) currently emits nan, and printing sympify_petab("x / 0") emits zoo*x. Neither can be read back as valid PEtab math. Add printer handlers that raise a descriptive ValueError for NaN and complex infinity, including when they occur inside larger expressions. Real positive/negative infinity keep their existing representation.

Tests exercise both the convenience function and PetabStrPrinter directly, including multiplication, unevaluated addition and piecewise branches. All 12 rejection cases fail before the fix; two infinity round-trip controls pass before and after. The documented exception and changelog are included.

Validation on Windows / Python 3.12:

  • Complete math module, including the official PEtab math cases: 196 passed.
  • v1 suite excluding test_priors.py (optional benchmark_models_petab dependency unavailable): 401 passed, 2 skipped, one remote-download TLS failure. That single test passed on retry.
  • v2 core/calculation/experiments/mapping modules: 103 passed. Other v2 modules were not run.
  • All applicable configured pre-commit hooks pass, including pinned Ruff lint/format; git diff --check passes.

Implemented and validated with OpenAI Codex assistance. Ready for review.

@ChenYueqi2024
ChenYueqi2024 requested a review from a team as a code owner November 19, 2026 12:02
Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

petab_math_str writes nan and zoo, which are not valid PEtab

2 participants