From e06e5c1bdd48b1939b0a16797b4b9f786018393b Mon Sep 17 00:00:00 2001 From: Ayush Shah Date: Wed, 20 Mar 2024 11:35:52 +0530 Subject: [PATCH] Fixes 15544: Histogram not working for more than 15 units (#15617) --- ingestion/src/metadata/utils/helpers.py | 2 ++ ingestion/tests/unit/test_helpers.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/ingestion/src/metadata/utils/helpers.py b/ingestion/src/metadata/utils/helpers.py index f218c611244..7635ae95a1f 100644 --- a/ingestion/src/metadata/utils/helpers.py +++ b/ingestion/src/metadata/utils/helpers.py @@ -346,6 +346,8 @@ def format_large_string_numbers(number: Union[float, int]) -> str: units = ["", "K", "M", "B", "T"] constant_k = 1000.0 magnitude = int(floor(log(abs(number), constant_k))) + if magnitude >= len(units): + return f"{int(number / constant_k**magnitude)}e{magnitude*3}" return f"{number / constant_k**magnitude:.3f}{units[magnitude]}" diff --git a/ingestion/tests/unit/test_helpers.py b/ingestion/tests/unit/test_helpers.py index ded406b8292..b125ad68eaf 100644 --- a/ingestion/tests/unit/test_helpers.py +++ b/ingestion/tests/unit/test_helpers.py @@ -157,6 +157,12 @@ class TestHelpers(TestCase): assert format_large_string_numbers(1000000) == "1.000M" assert format_large_string_numbers(1000000000) == "1.000B" assert format_large_string_numbers(1000000000000) == "1.000T" + assert format_large_string_numbers(10000000000000) == "10.000T" + assert format_large_string_numbers(100000000000000) == "100.000T" + assert format_large_string_numbers(1000000000000000) == "1e15" + assert format_large_string_numbers(10000000000000000) == "10e15" + assert format_large_string_numbers(100000000000000000) == "100e15" + assert format_large_string_numbers(1000000000000000000) == "1e18" def test_find_suggestion(self): """we can get one possible suggestion"""