Skip to content

Multiply and divide a Quantity by a number - #118

Merged
ruscoder merged 1 commit into
masterfrom
fix/quantity-multiplication
Dec 4, 2026
Merged

ruscoder merged 1 commit into
masterfrom
fix/quantity-multiplication

Conversation

@ruscoder

@ruscoder ruscoder commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Closes #117

* and / accept a Quantity operand: n * q, q * n and q / n keep the Quantity's unit, as in fhirpath.js, for literals and for FHIR Quantities from resource data. q / 0 returns empty, like number division.

Multiplying or dividing two Quantities, or dividing a number by a Quantity, raises a readable error; it needs UCUM unit algebra and is left for later, together with Quantity + Quantity. div and mod stay number-only, as in fhirpath.js.

The number, boolean and singleton checks format the rejected value with format_error_value, so a Quantity, date or resource operand gives "Expected number, got: ..." instead of a TypeError from json.dumps.

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.81%. Comparing base (e8ab5bd) to head (ef89c9f).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
fhirpathpy/engine/__init__.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #118      +/-   ##
==========================================
+ Coverage   90.77%   90.81%   +0.03%     
==========================================
  Files          27       27              
  Lines        3761     3776      +15     
==========================================
+ Hits         3414     3429      +15     
  Misses        347      347              
Flag Coverage Δ
unittests 90.81% <94.44%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ruscoder
ruscoder force-pushed the fix/quantity-multiplication branch from 6892a95 to ef89c9f Compare December 4, 2026 17:14
@ruscoder
ruscoder merged commit 95e4f14 into master Dec 4, 2026
10 checks passed
This was referenced Dec 4, 2026
@ruscoder
ruscoder deleted the fix/quantity-multiplication branch December 4, 2026 17:32
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.

Multiplying or dividing a Quantity by a number raises TypeError

1 participant