Skip to content

extract_numbers.py: 'FY2023 to' parses as 2,023,000,000,000,000 — a lone letter is accepted as a magnitude suffix #338

Description

@AB2006-personal

Summary

skills/ib-check-deck/scripts/extract_numbers.py reads a four-digit year plus
the first letter of the following word as a magnitude-suffixed number.

The sentence "Revenue grew from $100.0 million in FY2023 to $120.0 million in
FY2024."
yields a third figure: 2023t → 2,023,000,000,000,000, i.e. two
quadrillion dollars, categorised as revenue.

The t comes from the word "to".

Cause

# lines 118–125
r'(?P<number>[\d,]+(?:\.\d+)?)'
r'\s*'
r'(?P<unit>%|bps|x|'
r'[Tt]rillion|[Bb]illion|[Mm]illion|[Tt]housand|'
r'[TBMKtbmk]n?|mm|MM)?'   # a LONE letter counts as a magnitude
r'(?!\d)'                  # stops a following DIGIT, but not a following LETTER

\s* lets the unit sit across the space, [TBMKtbmk] accepts the bare t, and
(?!\d) only rules out a following digit — so ... 2023 to ... matches with
number=2023, unit=t.

Reproduce

from extract_numbers import extract_numbers
for n in extract_numbers("Revenue grew from $100.0 million in FY2023 to $120.0 million in FY2024."):
    print(n.value, n.unit, n.normalized, n.category)
$100.0million  USD_million             100000000  revenue
2023t          t          2023000000000000000     revenue   <-- 2.023e15
$120.0million  USD_million             120000000  revenue

Any "from FY20XX to FY20YY" sentence — routine in a deck — injects one. The
figure then dominates find_inconsistencies, since it is compared against real
revenue in the same category.

Suggested fix

Two changes, either of which kills this case; both together are safer:

  1. Require a non-letter after the unit, not just a non-digit:
    r'(?![A-Za-z0-9])'
  2. Reject a bare four-digit year carrying neither a currency symbol nor a
    unit — 1900–2099 with no $/€/£ and no suffix is a date:
    if re.fullmatch(r'(?:19|20)\d{2}', raw) and not currency and not unit:
        continue

Keep the genuine suffixes working: $1.2bn, $300m, 45k must still parse.

Scope

Two copies on main:

  • plugins/vertical-plugins/financial-analysis/skills/ib-check-deck/scripts/extract_numbers.py
  • plugins/agent-plugins/pitch-agent/skills/ib-check-deck/scripts/extract_numbers.py

Related but separate defect filed alongside this one (period-blind grouping).
Happy to open a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions