"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(entities): refuse an ambiguous single-dot cash flow amount
Lanre Shittuacde2c47e649
diff --git a/agent/src/entities/ingest.py b/agent/src/entities/ingest.pyindex 683f3b57f..bc08435dd 100644--- a/agent/src/entities/ingest.py+++ b/agent/src/entities/ingest.py@@ -149,7 +149,10 @@ def _to_plain_number(text: str, decimal_separator: str | None) -> str:Raises:ValueError: If the value uses a single comma whose role cannot bedetermined -- ``"1,234"`` is 1234 in a US export and 1.234 in a- European one, and the data cannot say which.+ European one, and the data cannot say which. The same applies to+ a single dot followed by exactly three digits -- ``"12.000"`` is+ 12 in a US export and 12000 in a European one, since European+ grouping always groups digits in threes."""if decimal_separator is not None:grouping = "," if decimal_separator == "." else "."@@ -171,6 +174,16 @@ def _to_plain_number(text: str, decimal_separator: str | None) -> str:f"{text.replace(',', '.')} (comma is the decimal separator); pass ""decimal_separator='.' or decimal_separator=',' to say which")+ if has_dot and text.count(".") == 1 and len(text.rpartition(".")[2]) == 3:+ # A lone dot followed by anything other than exactly three digits can+ # only be a decimal point -- European grouping never uses a group of+ # that width. Three digits is where it turns genuinely ambiguous.+ raise ValueError(+ f"{text!r} uses a single dot followed by three digits and could "+ f"be either {text.replace('.', '')} (dot groups thousands) or "+ f"{text} (dot is the decimal separator); pass "+ "decimal_separator='.' or decimal_separator=',' to say which"+ )return textdiff --git a/agent/tests/test_entities_spine.py b/agent/tests/test_entities_spine.pyindex a83f2bc9f..a9855cac9 100644--- a/agent/tests/test_entities_spine.py+++ b/agent/tests/test_entities_spine.py@@ -447,6 +447,25 @@ def test_load_cashflows_refuses_an_ambiguous_single_comma(tmp_path):assert load_cashflows(path, decimal_separator=",")[0].amount == pytest.approx(1.234)+def test_load_cashflows_refuses_an_ambiguous_single_dot(tmp_path):+ """'12.000' is 12 in a US export and 12000 in a European one."""+ path = _write_csv(+ tmp_path, "flows.csv", 'date,amount,kind,currency\n2024-03-31,"12.000",coupon,USD\n'+ )+ with pytest.raises(CashFlowIngestError, match="decimal_separator"):+ load_cashflows(path)+ assert load_cashflows(path, decimal_separator=".")[0].amount == pytest.approx(12.0)+ assert load_cashflows(path, decimal_separator=",")[0].amount == pytest.approx(12000.0)+++def test_load_cashflows_accepts_an_unambiguous_single_dot(tmp_path):+ """A dot not followed by exactly three digits can only be a decimal point."""+ path = _write_csv(+ tmp_path, "flows.csv", 'date,amount,kind,currency\n2024-03-31,"123.45",coupon,USD\n'+ )+ assert load_cashflows(path)[0].amount == pytest.approx(123.45)++def test_load_cashflows_rejects_an_invalid_decimal_separator(tmp_path):path = _write_csv(tmp_path, "flows.csv", "date,amount,kind,currency\n2024-03-31,10,coupon,USD\n"