One function

parse in scrapinghub/number-parser

The author described this change as Fix and test cases for issue #76 - white space around separators consumed after numbers (#77). It counts as a record because the check below fails on the code as it stood at a61bbdfe2 and passes on 034d5ef05, with nothing else changed between the two runs.

Fix saved2022-11-10
Sharing licenceBSD-3-Clause · LICENSE
Change size+7 1

What the code was meant to do, written into the code itself as a docstring

Converts all the numbers in a sentence written in natural language to their numeric type while keeping the other words unchanged. Returns the transformed string.

The change

1313 final_sentence = []
1414 current_sentence = []
1515 tokens_taken = []
16+ pop_last_space = True
1617
1718 def _build_and_add_number(pop_last_space=False):
1819 if tokens_taken:
3233 if not compare_token.strip():
3334 if not tokens_taken:
3435 current_sentence.append(token)
36+ pop_last_space = True
37+ else:
38+ pop_last_space = False
3539 continue
3640
3741 if compare_token in SENTENCE_SEPARATORS:
38- _build_and_add_number(pop_last_space=True)
42+ _build_and_add_number(pop_last_space=pop_last_space)
3943 current_sentence.append(token)
4044 final_sentence.extend(current_sentence)
4145 current_sentence = []
5963
6064 _build_and_add_number()
6165 current_sentence.append(token)
66+
67+ pop_last_space = True
6268
6369 _build_and_add_number()
6470

The check that tells the two apart

failpass·tests/test_language_en.py::test_parse_separators_and_spacing[one

Check file tests/test_language_en.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before ita61bbdfe205dd22025c7c68155c158c83abc57ee
Broken version dated2022-10-31
Modulenumber_parser.parser
Units changedparse
Fingerprintafb7fb836ca4b67a
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.