{"record":{"id":"9792932cf5460ee2","repo":"HKUDS/Vibe-Trading","slug":"comps-run-comps-duplicate-peer-names-in-names","errorCode":null,"errorMessage":"comps.run_comps: duplicate peer names in {names}","messagePattern":"comps\\.run_comps: duplicate peer names in (.+?)","errorType":"exception","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/comps.py","lineNumber":1178,"sourceCode":"            the same `eps_basis` (mixing GAAP and adjusted EPS across the\n            comp set would skew the P/E distribution by whatever one-time\n            items the adjustment removes, the same kind of silent distortion\n            the calendarisation-policy rule exists to prevent).\n        MissingInputError: (propagated from `calendarise_metric`) if any\n            peer's or the target's fiscal-period data lacks a field\n            `calendarisation_policy` needs.\n    \"\"\"\n    if calendarisation_policy not in CALENDARISATION_POLICIES:\n        raise ValuationError(\n            f\"comps.run_comps: unknown calendarisation_policy {calendarisation_policy!r}, \"\n            f\"must be one of {CALENDARISATION_POLICIES}\"\n        )\n    if len(peers) == 0:\n        raise MissingInputError((\"peers\",), \"comps.run_comps\")\n\n    names = [peer.name for peer in peers]\n    if len(set(names)) != len(names):\n        raise ValuationError(f\"comps.run_comps: duplicate peer names in {names}\")\n\n    all_bases = {peer.eps_basis for peer in peers} | {target.eps_basis}\n    if len(all_bases) > 1:\n        raise ValuationError(\n            \"comps.run_comps: mixed eps_basis across the comp set \"\n            f\"{sorted(all_bases)} -- every peer and the target must declare the \"\n            \"same EPS basis, or the P/E distribution mixes GAAP and adjusted \"\n            \"earnings\"\n        )\n\n    peer_multiples = tuple(peer_multiple_set(peer, calendarisation_policy) for peer in peers)\n    distributions = {\n        name: multiple_distribution(name, peer_multiples) for name in MULTIPLE_NAMES\n    }\n\n    calendarised_target = {\n        \"ebitda\": calendarise_metric(\n            target.ebitda, calendarisation_policy, metric_name=\"ebitda\", company_name=target.name","sourceCodeStart":1160,"sourceCodeEnd":1196,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/comps.py#L1160-L1196","documentation":"run_comps rejects a peer list containing duplicate names. Peer names are the identity used for reporting, exclusion lists, and cross-referencing, so two peers with the same name would silently overwrite/confuse results.","triggerScenarios":"Passing peers=[CompPeer(name='Apple',...), CompPeer(name='Apple',...)] — e.g. the same company fetched from two sources, or name collisions after normalization.","commonSituations":"Merging peer lists from multiple vendors without deduping; two share classes of one company mapped to the same display name; retries appending duplicates.","solutions":["Dedupe by name (or a canonical identifier) before calling run_comps.","If two entries are genuinely distinct companies, disambiguate names (e.g. append ticker or country).","Check for the same ticker appearing twice in the input universe."],"exampleFix":"# before\npeers = vendor_a_peers + vendor_b_peers  # dupes\n\n# after\nseen = set()\npeers = [p for p in vendor_a_peers + vendor_b_peers if not (p.name in seen or seen.add(p.name))]","handlingStrategy":"validation","validationCode":"names = [p.name for p in peers]\nif len(set(names)) != len(names):\n    raise ValueError(f'duplicate peer names: {sorted(names)}')","typeGuard":"def no_duplicate_names(peers):\n    names = [p.name for p in peers]\n    return len(set(names)) == len(names)","tryCatchPattern":"except ValuationError as e:\n    if 'duplicate peer names' in str(e):\n        peers = dedupe_by_name(peers)\n        result = run_comps(target, peers)","preventionTips":["Dedupe merged vendor lists by canonical ID","Disambiguate same-name companies with ticker suffixes"],"tags":["valuation","duplicates","peer-set","comps"],"backgroundTag":"duplicate-entries","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}