Skip to content

Fix silent 0.0 return on number parse failure in extract_numbers.py#14

Open
Pran-Ker wants to merge 1 commit intoanthropics:mainfrom
Pran-Ker:fix/extract-numbers-silent-zero-failure
Open

Fix silent 0.0 return on number parse failure in extract_numbers.py#14
Pran-Ker wants to merge 1 commit intoanthropics:mainfrom
Pran-Ker:fix/extract-numbers-silent-zero-failure

Conversation

@Pran-Ker
Copy link

Summary

  • normalize_number() returned 0.0 when float() conversion failed, silently converting invalid input into a meaningful financial value
  • In financial contexts, zero and "unparseable" are very different — a false zero could create incorrect inconsistency groupings in find_inconsistencies() or mask data quality issues
  • Now returns None on parse failure; unparseable entries are skipped entirely from the extraction pipeline

Changes

  • normalize_number(): Returns None instead of 0.0 on ValueError, with updated return type Optional[float]
  • NumberInstance.normalized: Type updated to Optional[float] to reflect that values may not always be parseable
  • extract_numbers(): Skips entries where normalized is None so invalid data never enters the pipeline
  • find_inconsistencies(): Added None guard on the division used for percentage-diff grouping

Test plan

  • Run extract_numbers.py on a presentation with valid numbers — output unchanged
  • Run on content with malformed number strings — entries are skipped instead of appearing as 0.0
  • Run with --check flag — inconsistency detection still works correctly
  • Verify no regressions in number grouping logic

🤖 Generated with Claude Code

normalize_number() returned 0.0 when float conversion failed,
silently converting invalid data into a meaningful financial
value. In financial contexts, zero and invalid are very
different — a false zero could create incorrect inconsistency
groupings or mask data quality issues.

Changes:
- Return None instead of 0.0 on parse failure
- Skip unparseable numbers in extract_numbers() pipeline
- Guard division in find_inconsistencies() against None values
- Update type annotations to reflect Optional[float]
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.

1 participant