{"record":{"id":"ef788fc3aac26662","repo":"QuantConnect/Lean","slug":"expected-symbol-expected-symbol-at-index-i-on","errorCode":null,"errorMessage":"Expected symbol {expected_symbol} at index  {i} on {date}, but got {symbol}","messagePattern":"Expected symbol (.+?) at index  (.+?) on (.+?), but got (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FutureUniverseHistoryRegressionAlgorithm.py","lineNumber":49,"sourceCode":"        if historical_futures_data_df.index.levshape[0] != 3:\n            raise RegressionTestException(f\"Expected 3 futures chains from history request, \"\n                                          f\"but got {historical_futures_data_df.index.levshape[1]}\")\n\n        for date in historical_futures_data_df.index.levels[0]:\n            expected_chain = list(self.future_chain_provider.get_future_contract_list(future, date))\n            expected_chain_count = len(expected_chain)\n\n            actual_chain = historical_futures_data_df.loc[date]\n            actual_chain_count = len(actual_chain)\n\n            if expected_chain_count != actual_chain_count:\n                raise RegressionTestException(f\"Expected {expected_chain_count} futures in chain on {date}, \"\n                                              f\"but got {actual_chain_count}\")\n\n            for i, symbol in enumerate(actual_chain.index):\n                expected_symbol = expected_chain[i]\n                if symbol != expected_symbol:\n                    raise RegressionTestException(f\"Expected symbol {expected_symbol} at index \"\n                                                  f\" {i} on {date}, but got {symbol}\")\n","sourceCodeStart":31,"sourceCodeEnd":51,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FutureUniverseHistoryRegressionAlgorithm.py#L31-L51","documentation":"Order-sensitive symbol check inside the same FutureUniverse history loop. After counts match, the test walks actual_chain.index position-by-position and compares each Symbol against expected_chain[i]. The first position where they differ aborts.","triggerScenarios":"The history result orders contracts differently from future_chain_provider.get_future_contract_list (e.g. by expiry vs by symbol string); a contract added/removed shifting positions; Symbol equality failing due to canonical vs mapped differences.","commonSituations":"Sort-order changes between engine versions; data refreshes inserting a contract mid-chain; Symbol comparison mismatch when one side is a continuous canonical and the other a mapped contract.","solutions":["Print expected_chain and list(actual_chain.index) side by side to find the divergent position.","Confirm both sources sort by the same key (typically expiry then strike).","Check Symbol equality semantics — compare .underlying / .id rather than the full object if mapping differs.","If sort order changed intentionally, realign the regression rather than reordering data."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Detect ordering divergence before raising\nfor date in df.index.levels[0]:\n    expected = list(self.future_chain_provider.get_future_contract_list(future, date))\n    actual = list(df.loc[date].index)\n    for i, (e, a) in enumerate(zip(expected, actual)):\n        if e != a:\n            self.debug(f\"Symbol order differs at {i} on {date}: expected={e} actual={a}\")","typeGuard":"def chains_same_order(provider, future, df) -> bool:\n    for d in df.index.levels[0]:\n        exp = list(provider.get_future_contract_list(future, d))\n        act = list(df.loc[d].index)\n        if exp != act:\n            return False\n    return True","tryCatchPattern":null,"preventionTips":["Confirm both sources sort contracts by the same key.","Compare Symbol.id or Symbol.underlying when mapping differs.","Refresh data if contracts were inserted/removed.","Log full expected vs actual lists at the first divergence."],"tags":["quantconnect","futures","future-universe","symbol-ordering","history-request","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}