Repository navigation
A number in accounting parentheses is read as negative, so "(1,234)" is -1234 instead of no value - #1422
Open
rudycelekli wants to merge 1 commit into
Open
A number in accounting parentheses is read as negative, so "(1,234)" is -1234 instead of no value#1422rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
…is -1234 instead of no value Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
WaylandYang
requested changes
Oct 25, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
The idea is right, but the text after ) isn't checked: "(1) 1,200 employees" now reads -1 and "(2024) 500" reads -2024, where dev read no value. Please accept only an empty tail or a unit/magnitude/% after the parenthesis, and add those two cases as negative tests. Also, with #1423, "HK$(300) million" still reads nothing, so one of the two needs to accept a - after the currency code. Please rebase after #1416.
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.
Why
Financial statements write a negative amount in parentheses:
(1,234),$(1.2) billion,(12.5%). The SEC filings the HTML table handling was measured on (the NVIDIA report cited inhtml.rs) are full of them. Net losses, cash outflows and declines all look like this.When extraction copies such a cell as the value of a
numberattribute,normalize_attr_valuecannot read it. The plain parse fails on the parentheses.parse_leading_quantityfinds no digit at the start. The value is dropped, so the typed graph keeps every positive line of a table and loses every negative one.What changes
The lenient quantity scan (
scan_quantitywithstrict = false, used bynormalize_attr_valueandattribute_value) rewrites an accounting negative before reading it. The value must be a number in parentheses, optionally preceded by a currency, with the rest after the closing parenthesis kept:(1,234)→-1,234,$(1.2) billion→$-1.2 billion,(350)万元→-350万元.Anything else in parentheses is left alone, such as
(see note 4), orQ3 (12)where the text before the parenthesis is not a currency. The strict scan that decides whether an object name is a value (literal_object) is unchanged, so a named(1984)is still a thing.How it was checked
A new test,
an_accounting_negative_is_read_as_negative:(1,234)is-1234.$(1.2) billionis-1200000000.(12.5%)is-12.5.(350)万元under万元is-350.(see note 4)andQ3 (12)still read as no value.literal_object("(1984)", true)is still false.Results:
cargo test -p utopia-extract --lib: 112 passed.left: None,right: Some(Number(-1234.0)).cargo fmt --all --checkandcargo clippy -p utopia-extract --all-targets -- -D warningspass.Before review
git commit -s)cargo fmt --all --check,cargo clippyandcargo testpass for the touched crate