Skip to content

Fix: parse_fraction accepts zero denominator and misses capitalized separators - #143

Open
yamilmaud wants to merge 2 commits into
scrapinghub:masterfrom
yamilmaud:fix_DC-1477_parse_fraction_zero_denominator_returns_1_0_capitalized_separators_not_matched
Open

yamilmaud wants to merge 2 commits into
scrapinghub:masterfrom
yamilmaud:fix_DC-1477_parse_fraction_zero_denominator_returns_1_0_capitalized_separators_not_matched

Conversation

@yamilmaud

Copy link
Copy Markdown

Summary

  • parse_fraction returned "N/0" for a zero denominator (e.g. parse_fraction('one over zero', 'en') returned '1/0') instead of rejecting the input.
  • The fraction separator was matched with a case-sensitive substring search, so capitalized separators like "Over" were not recognized (parse_fraction('One Over Two', 'en') returned None).
  • As a side fix, the separator search now uses word boundaries, so "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

  • Added regression tests in tests/test_number_parsing.py::test_parse_fraction covering: 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

…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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_fraction: zero denominator returns 1/0; capitalized separators are not matched

1 participant