Repository navigation
Fix: parse_fraction accepts zero denominator and misses capitalized separators - #143
Open
yamilmaud wants to merge 2 commits into
Conversation
…eparators
- Reject fractions whose denominator is 0 instead of returning "N/0".
- Match fraction separators ("divided by", "over", "by") case-insensitively
and on word boundaries, so capitalized input parses correctly and "by"
no longer matches inside unrelated words like "baby".
Fixes scrapinghub#125
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
3 tasks done
ubuntu-latest moved to Ubuntu 26.04, which setup-python has no Python 3.9 build for. Pin that matrix entry to ubuntu-22.04, same fix applied in scrapinghub#141. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
parse_fractionreturned"N/0"for a zero denominator (e.g.parse_fraction('one over zero', 'en')returned'1/0') instead of rejecting the input."Over"were not recognized (parse_fraction('One Over Two', 'en')returnedNone)."by"no longer incorrectly matches inside unrelated words like"baby".Fixes #125
Jira: https://zyte.atlassian.net/browse/DC-1477
(Supersedes #142, closed when its source branch was renamed.)
Test plan
tests/test_number_parsing.py::test_parse_fractioncovering: zero denominator, capitalized separators, and "by" inside "baby".pytest tests/passes (374 tests).pre-commit run --all-files(ruff check/format) passes.🤖 Generated with Claude Code