Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big prefix bugfix #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions numerizer/numerizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ def _repl_big_prefixes(m):
try:
group_1_numberized = int(m.group(1))
except ValueError:
group_1_numberized = float(m.group(1))
repl = '<num>' + str(int(v * group_1_numberized))
try:
group_1_numberized = float(m.group(1))
except ValueError:
# Fallback in case group_1 is unparseable like ". million"
group_1_numberized = None
if group_1_numberized is not None:
repl = "<num>" + str(int(v * group_1_numberized))
else:
repl = str(v)
else:
repl = str(v)
except IndexError:
Expand Down
2 changes: 1 addition & 1 deletion test_numerize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_straight_parsing():
99_999: "ninety nine thousand nine hundred ninety nine",
100_000: "100 thousand",
250_000: "two hundred fifty thousand",
1_000_000: ["one million", "1.0 million"],
1_000_000: ["one million", "1.0 million", ". Million"],
1_200_000: "1.2 million",
1_250_007: "one million two hundred fifty thousand and seven",
1_000_000_000: "one billion",
Expand Down