HKUDS/Vibe-Trading · error · ValueError
amount must be a finite number, got {self.amount!r}; a missi
Error message
amount must be a finite number, got {self.amount!r}; a missing value must be fixed at the source, not carried as NaN What it means
After float() coercion succeeds, CashFlow rejects amounts that are NaN or the infinities, because financial aggregation would silently propagate garbage. The error message states the library's policy: missing values must be fixed at the source, never carried as NaN.
Source
Thrown at agent/src/entities/cashflow.py:163
"""Normalize every field and enforce the sign convention.
Raises:
ValueError: If the date is unsupported, the amount is not finite,
the currency or kind is blank, or the amount's sign contradicts
a canonical kind in ``KIND_DIRECTION``.
"""
object.__setattr__(self, "date", normalize_date(self.date))
object.__setattr__(self, "kind", normalize_kind(self.kind))
object.__setattr__(self, "currency", normalize_currency(self.currency))
try:
amount = float(self.amount)
except (TypeError, ValueError) as exc:
raise ValueError(
f"amount must be numeric, got {self.amount!r}"
) from exc
if not math.isfinite(amount):
raise ValueError(
f"amount must be a finite number, got {self.amount!r}; a missing "
"value must be fixed at the source, not carried as NaN"
)
object.__setattr__(self, "amount", amount)
required_sign = KIND_DIRECTION.get(self.kind)
if required_sign is not None and amount != 0.0:
if (amount > 0) != (required_sign > 0):
direction = "positive (cash in)" if required_sign > 0 else "negative (cash out)"
raise ValueError(
f"kind={self.kind!r} must have a {direction} amount under the "
f"holder-perspective sign convention, got {amount!r}. Flip the "
"sign, or use a distinct kind if this flow is genuinely "
"two-directional (e.g. 'recallable_distribution')."
)
if not isinstance(self.metadata, Mapping):
raise ValueError(View on GitHub (pinned to 80ffdda44c)
Solutions
- Filter or repair NaN/inf rows before constructing CashFlow (df = df.dropna(subset=['amount']) or replace with a corrected source value)
- If missingness is legitimate (e.g. an unreported period), exclude that flow rather than encoding it as NaN
- Add an ingest-time assert math.isfinite(x) to fail fast with row context
Example fix
# before
rows = df.to_dict('records')
flows = [CashFlow(**r) for r in rows] # NaN amount -> ValueError
# after
import math
rows = df.to_dict('records')
flows = [CashFlow(**r) for r in rows if math.isfinite(float(r['amount']))] Defensive patterns
Strategy: validation
Validate before calling
import math clean_rows = [r for r in rows if math.isfinite(float(r['amount']))]
Type guard
def is_finite_number(v) -> bool:
return isinstance(v, (int, float)) and math.isfinite(v) Try / catch
try:
CashFlow(date=d, kind=k, amount=a, currency=c)
except ValueError as e:
if 'finite number' in str(e):
handle_missing_value(row) # drop, backfill from source, or alert Prevention
- dropna/subset on amount before entity creation
- Never encode missing data as NaN — exclude the row or fix upstream
- Assert finiteness in loader unit tests
When it happens
Trigger: CashFlow(amount=float('nan')), amount=float('inf'), or an amount parsed from the string 'NaN'/'inf' (float() accepts these).
Common situations: Pandas DataFrames with missing data converted via .to_dict('records') (NaN fills nulls); CSV cells containing 'NaN', 'n/a', or 'inf'; computations that divide by zero producing inf before entity creation.
Related errors
- kind={self.kind!r} must have a {direction} amount under the
- pre_translated=True asserts the flows were already converted
- start {lower} is after end {upper}
- flows[{index}]: {exc}
- flow_timing must be {FLOW_TIMING_END!r} or {FLOW_TIMING_STAR
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/0c5206c5eaf0a56a.
Report an issue: GitHub.