QuantConnect/Lean · error · AssertionError
History call failed: {e}
Error message
History call failed: {e} What it means
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.
Source
Thrown at Algorithm.Python/PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm.py:36
### dataframe without raising exceptions. The main exception in this case was a "non-unique multi-index" error due to trades adn quote ticks with
### duplicated timestamps.
### </summary>
class PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 8)
self.set_end_date(2013, 10, 8)
spy = self.add_equity("SPY", Resolution.MINUTE).symbol
subscriptions = [x for x in self.subscription_manager.subscriptions if x.symbol == spy]
if len(subscriptions) != 2:
raise AssertionError(f"Expected 2 subscriptions, but found {len(subscriptions)}")
history = pd.DataFrame()
try:
history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)
except Exception as e:
raise AssertionError(f"History call failed: {e}")
if history.shape[0] == 0:
raise AssertionError("SPY tick history is empty")
if not np.array_equal(history.columns.to_numpy(), ['askprice', 'asksize', 'bidprice', 'bidsize', 'exchange', 'lastprice', 'quantity']):
raise AssertionError("Unexpected columns in SPY tick history")
self.quit()
View on GitHub (pinned to d2c3659f87)
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.
Example fix
# before — any History failure becomes an opaque AssertionError
try:
history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)
except Exception as e:
raise AssertionError(f"History call failed: {e}")
# after — branch on the failure cause so missing data is distinguished from real errors
try:
history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)
except Exception as e:
msg = str(e).lower()
if 'not found' in msg or 'does not exist' in msg or 'no data' in msg:
# tick data absent for this date — degrade gracefully
self.debug(f"Tick data unavailable for {spy}: {e}")
history = pd.DataFrame()
else:
raise AssertionError(f"History call failed unexpectedly: {e}") Defensive patterns
Strategy: try-catch
Validate before calling
# Validate data availability before the history call
from datetime import timedelta
if not self.securities[spy].has_data:
self.debug(f"No data configured for {spy}; skipping tick history")
else:
try:
history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)
except Exception as e:
self.debug(f"Tick history failed (expected if no tick data): {e}") Try / catch
try:
history = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)
except Exception as e:
# Distinguish missing data from real pipeline errors
if 'could not be found' in str(e).lower() or 'does not exist' in str(e).lower():
self.debug(f"Tick data unavailable for {spy}: {e}")
else:
raise # unexpected pipeline error — propagate Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected columns in SPY tick history
- Expected 2 subscriptions, but found {len(subscriptions)}
- SPY tick history is empty
- Empty history data frame for {symbol}
- Could not unstack df. Columns: {', '.join(df.columns)} | {co
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/3246eef7373f4ddc.
Report an issue: GitHub.