Skip to content

fix(calculator): accept signed values and reject trailing input in conversions - #737

Merged
rng1995 merged 5 commits into
NVIDIA:mainfrom
dhananjay6561:fix/calculator-signed-values
Nov 17, 2026
Merged

rng1995 merged 5 commits into
NVIDIA:mainfrom
dhananjay6561:fix/calculator-signed-values

Conversation

@dhananjay6561

Copy link
Copy Markdown
Contributor

Summary

The calculator reference skill parsed conversions and percentages with re.match(r"([\d.]+)..."). That rejected negative values (-40 celsius to fahrenheit failed with Error: invalid syntax) and, since the pattern wasn't anchored at the end, quietly ignored anything after a match: 10% of 50 + 5 printed Result: 5. A malformed number like 1.2.3 km to miles matched and then crashed with a ValueError traceback.

Both patterns now use re.fullmatch with a signed decimal number pattern:

  • -40 celsius to fahrenheit → -40 celsius = -40 fahrenheit, -10% of 50 → Result: -5
  • 10% of 50 + 5, 5 km to miles please and 1.2.3 km to miles are no longer treated as a conversion/percentage, so they get the usual Error: ... line and exit code 1 instead of a wrong answer or a traceback
  • the documented examples (100 celsius to fahrenheit, 15% of 200, 5 miles to km, plain arithmetic) give the same output as before

Fixes #735.

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes
  • Ran make lint
  • Ran make test
  • Ran make build
  • Did not add credentials, private datasets, or proprietary benchmark content

Tested on macOS 26.6 arm64, Python 3.14.7, on top of upstream d2cb1388.

  • pytest -n 0 tests/test_reference_calculator.py: 10 passed. Against the unchanged calc.py the same file has 7 failures (the four signed-value cases and the three trailing-input cases).
  • ruff check src tests and ruff format --check on the changed files: passed.
  • python -m build: built the sdist and wheel.
  • I didn't run the full make test suite; the change is limited to the standalone calculator script, which nothing else imports.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Copilot AI balanced review requested due to automatic review settings November 17, 2026 04:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this is a clean fix and I could reproduce all three problems on main: -40 celsius to fahrenheit and -10% of 50 failed with Error: invalid syntax, 10% of 50 + 5 printed Result: 5, and 1.2.3 km to miles died with a ValueError traceback. With this branch they give -40 celsius = -40 fahrenheit, Result: -5, and an Error: line with exit code 1.

I also checked that the documented examples (100 celsius to fahrenheit, 15% of 200, 5 miles to km, plain arithmetic, 5 % 3) print exactly what they did before, that mixed case still works, and that 5., .5 and +5 are accepted by the new number pattern. The grader reference trajectories that record calculator output (Result: 30 for 15% of 200, Result: -5 for 3 - 8) still match the script. The new test file fails 7 of 10 cases against the old script and passes 10 of 10 with the fix. Ruff check and format are clean, every commit is signed off, and the changelog entry is in the right place.

Looks good to me.

@dhananjay6561

Copy link
Copy Markdown
Contributor Author

@chrisknvidia thanks a lot for going through it that carefully, especially checking the grader trajectories. If there's nothing else, would you be able to approve and merge it?

…ing input

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
@dhananjay6561
dhananjay6561 force-pushed the fix/calculator-signed-values branch from f84f3c7 to abd4b5b Compare November 17, 2026 12:23

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution, @dhananjay6561. Reviewed abd4b5b9125d; no new actionable defects found. The signed-decimal pattern and full-string matching handle negative conversions/percentages and reject trailing or malformed input through the normal error path. I checked the documented examples and arithmetic fallback.

Validation: All 10 calculator regression tests passed.

Existing review feedback is positive; I have no additional change requests.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @dhananjay6561. Rechecked 4cbc364fe93e and the latest discussion. The delta from abd4b5b9125d only merges main's task-list fix (#680), its tests and changelog. Calculator source, its regression tests and dependencies are unchanged; no new actionable defects found.

Retained validation: all 10 calculator regression tests passed on abd4b5b9125d; I did not rerun them for this unrelated merge. Existing review feedback remains positive, and I have no additional change requests.

@rng1995
rng1995 merged commit 6b0a647 into NVIDIA:main Nov 17, 2026
25 checks passed
rng1995 added a commit to cf3901646/SkillEvaluator that referenced this pull request Nov 20, 2026
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
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.

[BUG]: Calculator reference skill rejects negative values in conversions and percentages and ignores trailing input

4 participants