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.
Projectscrapinghub/number-parser
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
| 13 | 13 | final_sentence = [] | |
| 14 | 14 | current_sentence = [] | |
| 15 | 15 | tokens_taken = [] | |
| 16 | + | pop_last_space = True | |
| 16 | 17 | ||
| 17 | 18 | def _build_and_add_number(pop_last_space=False): | |
| 18 | 19 | if tokens_taken: | |
| ⋯ | |||
| 32 | 33 | if not compare_token.strip(): | |
| 33 | 34 | if not tokens_taken: | |
| 34 | 35 | current_sentence.append(token) | |
| 36 | + | pop_last_space = True | |
| 37 | + | else: | |
| 38 | + | pop_last_space = False | |
| 35 | 39 | continue | |
| 36 | 40 | ||
| 37 | 41 | 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) | |
| 39 | 43 | current_sentence.append(token) | |
| 40 | 44 | final_sentence.extend(current_sentence) | |
| 41 | 45 | current_sentence = [] | |
| ⋯ | |||
| 59 | 63 | ||
| 60 | 64 | _build_and_add_number() | |
| 61 | 65 | current_sentence.append(token) | |
| 66 | + | ||
| 67 | + | pop_last_space = True | |
| 62 | 68 | ||
| 63 | 69 | _build_and_add_number() | |
| 64 | 70 | ||
The check that tells the two apart
fail→pass·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.