{"record":{"id":"97323f5ae81da216","repo":"HKUDS/Vibe-Trading","slug":"valuations-index-must-be-a-date-value-pair","errorCode":null,"errorMessage":"valuations[{index}] must be a (date, value) pair, got {type(item).__name__}","messagePattern":"valuations\\[(.+?)\\] must be a \\(date, value\\) pair, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/performance.py","lineNumber":308,"sourceCode":"            ``src.entities.models.normalize_date``, so ISO-8601 strings and\n            ``datetime`` instances are accepted.\n\n    Returns:\n        Pairs sorted by date, with at least two entries.\n\n    Raises:\n        ValueError: If fewer than two valuations were supplied, a pair is\n            malformed, a value is not finite, or a date repeats. A repeated\n            date is rejected rather than deduplicated because two different\n            marks for one day have no defensible ordering.\n    \"\"\"\n    if isinstance(valuations, Mapping):\n        raw_items: list[tuple[object, object]] = list(valuations.items())\n    else:\n        raw_items = []\n        for index, item in enumerate(valuations):\n            if isinstance(item, (str, bytes)) or not isinstance(item, Sequence):\n                raise ValueError(\n                    f\"valuations[{index}] must be a (date, value) pair, got \"\n                    f\"{type(item).__name__}\"\n                )\n            pair = tuple(item)\n            if len(pair) != 2:\n                raise ValueError(\n                    f\"valuations[{index}] must have exactly two elements \"\n                    f\"(date, value), got {len(pair)}\"\n                )\n            raw_items.append((pair[0], pair[1]))\n\n    if len(raw_items) < 2:\n        raise ValueError(\n            \"a return needs an opening and a closing valuation; got \"\n            f\"{len(raw_items)}\"\n        )\n\n    resolved: list[tuple[date, float]] = []","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/performance.py#L290-L326","documentation":"The performance return functions (time_weighted_return, modified_dietz_return, money_weighted_return) normalise a valuations iterable into (date, value) pairs. Each element must be a two-element sequence; passing a bare string/bytes or a non-sequence scalar at some index raises this error naming the index and the offending Python type.","triggerScenarios":"Calling time_weighted_return(['2024-01-01', '2024-12-31']) — a list of date strings instead of pairs; or [date(2024,1,1), 100.0, date(2024,12,31), 105.0] with interleaved flat values; strings are explicitly rejected so they are not expanded character-by-character.","commonSituations":"Reading a CSV row of alternating dates and values into a flat list; forgetting zip(dates, values); mixing a Mapping for some periods and flat lists for others in user input.","solutions":["Build pairs with zip: list(zip(dates, values)).","If you meant a mapping input, pass {'2024-01-01': 100.0, ...} which is supported.","Validate each element with isinstance(item, (tuple, list)) and len == 2 before calling."],"exampleFix":"# before\ntwr = time_weighted_return(['2024-01-01', '2024-06-30', '2024-12-31'])  # raises\n\n# after\ntwr = time_weighted_return([('2024-01-01', 100.0), ('2024-12-31', 105.0)])","handlingStrategy":"type-guard","validationCode":"vals = list(zip(dates, values))  # ensure pairs before calling\nassert all(isinstance(p, (tuple, list)) and len(p) == 2 for p in vals)","typeGuard":"from collections.abc import Sequence\ndef are_date_value_pairs(v) -> bool:\n    return all(\n        isinstance(i, Sequence) and not isinstance(i, (str, bytes)) and len(tuple(i)) == 2\n        for i in v\n    )","tryCatchPattern":"try:\n    r = time_weighted_return(valuations)\nexcept ValueError as e:\n    if 'must be a (date, value) pair' in str(e):\n        raise DataShapeError('valuations not paired') from e\n    raise","preventionTips":["Always construct valuations with zip(dates, values) or pass a Mapping.","Never hand-build flat interleaved lists.","Add a shape check in data prep."],"tags":["performance","valuation","input-validation","data-shape"],"backgroundTag":"invalid-argument-structure","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}