Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(entities): read dot digit grouping the way comma grouping is read

Rudy Celekli99b5a5e172dc
diff --git a/agent/src/entities/ingest.py b/agent/src/entities/ingest.py
index 10af9ed30..28c60bc45 100644
--- a/agent/src/entities/ingest.py
+++ b/agent/src/entities/ingest.py
@@ -146,6 +146,10 @@ def _to_plain_number(text: str, decimal_separator: str | None) -> str:
Returns:
The same number using ``.`` as the decimal separator and no grouping.
+ A separator that appears twice or more is always digit grouping: a number
+ carries at most one decimal separator, so ``"1,234,567"`` and
+ ``"1.234.567"`` are both 1234567 whichever locale wrote them.
+
Raises:
ValueError: If the value uses a single comma whose role cannot be
determined -- ``"1,234"`` is 1234 in a US export and 1.234 in a
@@ -165,6 +169,8 @@ def _to_plain_number(text: str, decimal_separator: str | None) -> str:
if text.rindex(".") > text.rindex(","):
return text.replace(",", "")
return text.replace(".", "").replace(",", ".")
+ if has_dot and text.count(".") > 1:
+ return text.replace(".", "") # 1.234.567 cannot be a decimal point
if has_comma:
if text.count(",") > 1:
return text.replace(",", "") # 1,234,567 cannot be a decimal comma
diff --git a/agent/tests/test_entities_spine.py b/agent/tests/test_entities_spine.py
index 3849f3e60..d721d387b 100644
--- a/agent/tests/test_entities_spine.py
+++ b/agent/tests/test_entities_spine.py
@@ -436,6 +436,29 @@ def test_load_cashflows_reads_european_grouping_without_mangling_it(tmp_path):
assert load_cashflows(path)[0].amount == pytest.approx(1234.50)
+def test_load_cashflows_reads_dot_grouping_with_no_fraction(tmp_path):
+ """'1.234.567' is 1234567, the same way '1,234,567' already is.
+
+ Two or more of the same separator cannot be a decimal point, so the number
+ is unambiguous whichever locale wrote it -- the multi-comma case is already
+ resolved that way. Without the matching dot rule the cell reaches float()
+ unchanged and the row fails as "not usable".
+ """
+ path = _write_csv(
+ tmp_path,
+ "flows.csv",
+ 'date,amount,kind,currency\n2024-03-31,"1.234.567",coupon,USD\n',
+ )
+ assert load_cashflows(path)[0].amount == pytest.approx(1234567.0)
+
+ comma = _write_csv(
+ tmp_path,
+ "commas.csv",
+ 'date,amount,kind,currency\n2024-03-31,"1,234,567",coupon,USD\n',
+ )
+ assert load_cashflows(comma)[0].amount == pytest.approx(1234567.0)
+
+
def test_load_cashflows_refuses_an_ambiguous_single_comma(tmp_path):
"""'1,234' is 1234 in a US export and 1.234 in a European one."""
path = _write_csv(