{"record":{"id":"3246eef7373f4ddc","repo":"QuantConnect/Lean","slug":"history-call-failed-e","errorCode":null,"errorMessage":"History call failed: {e}","messagePattern":"History call failed: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm.py","lineNumber":36,"sourceCode":"### dataframe without raising exceptions. The main exception in this case was a \"non-unique multi-index\" error due to trades adn quote ticks with\n### duplicated timestamps.\n### </summary>\nclass PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm(QCAlgorithm):\n    def initialize(self):\n        self.set_start_date(2013, 10, 8)\n        self.set_end_date(2013, 10, 8)\n\n        spy = self.add_equity(\"SPY\", Resolution.MINUTE).symbol\n\n        subscriptions = [x for x in self.subscription_manager.subscriptions if x.symbol == spy]\n        if len(subscriptions) != 2:\n            raise AssertionError(f\"Expected 2 subscriptions, but found {len(subscriptions)}\")\n\n        history = pd.DataFrame()\n        try:\n            history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\n        except Exception as e:\n            raise AssertionError(f\"History call failed: {e}\")\n\n        if history.shape[0] == 0:\n            raise AssertionError(\"SPY tick history is empty\")\n\n        if not np.array_equal(history.columns.to_numpy(), ['askprice', 'asksize', 'bidprice', 'bidsize', 'exchange', 'lastprice', 'quantity']):\n            raise AssertionError(\"Unexpected columns in SPY tick history\")\n\n        self.quit()\n","sourceCodeStart":18,"sourceCodeEnd":45,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm.py#L18-L45","documentation":"Regression assertion wrapping any exception thrown by self.history(Tick, spy, timedelta(days=1), Resolution.TICK). The algorithm deliberately catches Exception and re-raises it as an AssertionError with context, so any failure inside the history pipeline surfaces here rather than crashing the run with the raw exception. The 'e' carries the original message and type.","triggerScenarios":"The History(Tick, symbol, timedelta, Resolution.TICK) call raises — e.g. no tick data on disk for the requested date, a pandas/indexing error while building the frame (the non-unique multi-index error the algorithm's docstring mentions), a subscription that cannot serve Tick resolution, or a data-reader/zip failure for the symbol's factor files.","commonSituations":"Backtest environment lacks the tick data files for SPY for 2013-10-08. A pandas version change introduced a new exception shape during dataframe construction. The data folder path or symbol mapping is misconfigured so the data reader cannot locate files. Tick resolution was requested but the subscription only supports minute data.","solutions":["Read the captured exception message (the {e}) first — it names the actual failure (file not found, non-unique index, unsupported resolution).","If it is a missing-data error: confirm the tick data files exist in /Data for the symbol and date, and that the data folder is configured correctly.","If it is a pandas/indexing error: check the pandas version and whether the Lean dataframe-building code path changed; the non-unique multi-index case is the known historical trigger."],"exampleFix":"# before — any History failure becomes an opaque AssertionError\ntry:\n    history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\nexcept Exception as e:\n    raise AssertionError(f\"History call failed: {e}\")\n\n# after — branch on the failure cause so missing data is distinguished from real errors\ntry:\n    history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\nexcept Exception as e:\n    msg = str(e).lower()\n    if 'not found' in msg or 'does not exist' in msg or 'no data' in msg:\n        # tick data absent for this date — degrade gracefully\n        self.debug(f\"Tick data unavailable for {spy}: {e}\")\n        history = pd.DataFrame()\n    else:\n        raise AssertionError(f\"History call failed unexpectedly: {e}\")","handlingStrategy":"try-catch","validationCode":"# Validate data availability before the history call\nfrom datetime import timedelta\nif not self.securities[spy].has_data:\n    self.debug(f\"No data configured for {spy}; skipping tick history\")\nelse:\n    try:\n        history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\n    except Exception as e:\n        self.debug(f\"Tick history failed (expected if no tick data): {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\nexcept Exception as e:\n    # Distinguish missing data from real pipeline errors\n    if 'could not be found' in str(e).lower() or 'does not exist' in str(e).lower():\n        self.debug(f\"Tick data unavailable for {spy}: {e}\")\n    else:\n        raise  # unexpected pipeline error — propagate","preventionTips":["Confirm tick data files exist on disk for the requested symbol/date before requesting tick history.","Wrap history calls and branch on the exception message to separate missing-data from real failures.","Ensure the subscription actually supports Tick resolution for the symbol."],"tags":["quantconnect","lean","history","tick-data","pandas","regression-test","python"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}