Skip to content

A declared unit with a plural magnitude is read in that magnitude, so "$5 billion" under "USD millions" is 5000 - #1434

Open
rudycelekli wants to merge 1 commit into
deeplethe:devfrom
rudycelekli:extract-plural-unit
Open

rudycelekli wants to merge 1 commit into
deeplethe:devfrom
rudycelekli:extract-plural-unit

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Why

attribute_value converts a number into the attribute's declared unit. It finds the magnitude in the unit with magnitude, which knows million, thousand and so on in the singular only. Financial tables almost always label the column in the plural: "USD millions", "$ thousands", "thousands of dollars". With such a unit the magnitude is not found, the exponent falls back to 0, and the absolute value is stored as if it were already in millions:

  • "$5 billion" under "USD millions" is stored as 5000000000 instead of 5000.
  • "$2.5 million" under "$ thousands" is stored as 2500000 instead of 2500.

"USD million" (merged in #1417) and "million dollars" already work, so the same figure lands a million times too large only because the label has an s.

What changes

When reading the declared unit, a magnitude word may end in a plural s (millions, thousands, billions). That applies to both places the unit is read: the leading word ("thousands of dollars") and the trailing word ("USD millions"). The quantity parser for the value itself is unchanged, and the currency mismatch check still applies ("€30 million" under "USD millions" is still no value).

How it was checked

  • A new test, a_unit_with_a_plural_magnitude_is_read_in_that_magnitude, covers "USD millions", "$ thousands", "thousands of dollars", "Millions", and the currency mismatch.
  • With the fix reverted the test fails: left: Some(Number(5000000000.0)) right: Some(Number(5000.0)).
  • cargo test -p utopia-extract --lib: 113 passed.
  • cargo fmt -p utopia-extract --check and cargo clippy -p utopia-extract --all-targets -- -D warnings pass.

Before review

  • Every commit is signed off (git commit -s)
  • cargo fmt --all --check, cargo clippy and cargo test pass for the touched crate

… "$5 billion" under "USD millions" is 5000

Signed-off-by: Rudy Celekli <rudy@gradiahq.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.

1 participant