Repository navigation
fix(normalizer): read the whole part of money with cents correctly - #597
Merged
Merged
Conversation
The cents branch of _money took math.floor of the amount, so a negative amount lost one more unit: -$1.50 was read as "minus two dollars and fifty cents". It also pluralized the bill on the full amount, so $1.05 became "one dollars". Read the sign on its own, use the whole number of units for the words and for the plural. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Owner
|
Thanks @lbarrosby, good fix and coverage. Small nit: think this brings in duplicate |
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.
When an amount has cents,
_moneyinnormalization/english.pybuilds the spoken whole part fromint(math.floor(number))and the bill word fromplural(bill, count=number):-$1.50-£3.75$1.05€1.20floorrounds a negative amount down, so every negative amount with cents was read one unit too high. inflect pluralizes for any count other than 1, so1.05always got the plural. Whole amounts (-$5,$1.00) take the other branch and were already right.The cents branch now reads the sign on its own (
int(-0.25)would drop it), usesint(abs(number))for the words and the plural, and takes the cents from the absolute value.mathis no longer used in the module, so its import is gone.Testing
uv run pytestpasses locally (API changes)npm run test:webpasses locally (web player changes)npm run cpu:up/gpu:up), for inference or docker changesCHANGELOG.mdentry, if users will notice the changeFive new
CASESinapi/tests/test_normalizer.py(the four rows above plus-$0.25, which keeps "minus zero dollars and twenty-five cents"). All five fail on master and pass with the fix. I rantest_normalizer.py,test_normalizer_contract.pyandtest_normalizer_properties.py(159 passed) in a small venv with the locked inflect 7.5.0, without torch or model weights, so I did not tick the fulluv run pytestbox.ruff checkandruff format --checkare clean.AI disclosure: written with the help of Claude Code, reviewed and tested by me.