QuantConnect/Lean · error · RegressionTestException
Expected 3 futures chains from history request, but got {his
Error message
Expected 3 futures chains from history request, but got {historical_futures_data_df.index.levshape[1]} What it means
Regression check that a history(FutureUniverse, symbol, 3, flatten=True) call returns exactly 3 dated future chains. It inspects the pandas multi-index shape (levshape[0]) and asserts it equals 3. NOTE: the message prints levshape[1] (the contract level) while the comparison uses levshape[0] (the date level), so the diagnostic text is misleading.
Source
Thrown at Algorithm.Python/FutureUniverseHistoryRegressionAlgorithm.py:32
from AlgorithmImports import *
### <summary>
### Regression algorithm testing history requests for <see cref="FutureUniverse"/> type work as expected
### and return the same data as the futures chain provider.
### </summary>
class OptionUniverseHistoryRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013, 10, 11)
self.set_end_date(2013, 10, 11)
future = self.add_future(Futures.Indices.SP_500_E_MINI).symbol
historical_futures_data_df = self.history(FutureUniverse, future, 3, flatten=True)
# Level 0 of the multi-index is the date, we expect 3 dates, 3 future chains
if historical_futures_data_df.index.levshape[0] != 3:
raise RegressionTestException(f"Expected 3 futures chains from history request, "
f"but got {historical_futures_data_df.index.levshape[1]}")
for date in historical_futures_data_df.index.levels[0]:
expected_chain = list(self.future_chain_provider.get_future_contract_list(future, date))
expected_chain_count = len(expected_chain)
actual_chain = historical_futures_data_df.loc[date]
actual_chain_count = len(actual_chain)
if expected_chain_count != actual_chain_count:
raise RegressionTestException(f"Expected {expected_chain_count} futures in chain on {date}, "
f"but got {actual_chain_count}")
for i, symbol in enumerate(actual_chain.index):
expected_symbol = expected_chain[i]
if symbol != expected_symbol:
raise RegressionTestException(f"Expected symbol {expected_symbol} at index "
f" {i} on {date}, but got {symbol}")View on GitHub (pinned to d2c3659f87)
Solutions
- Widen the date window or raise the history bar count so 3 distinct future chains exist.
- Print historical_futures_data_df.index.levshape to confirm both levels before trusting the message text (it shows the wrong level).
- Verify the FutureUniverse type is supported for history in the current engine version.
- Ensure flatten=True is appropriate — without it the index arity differs.
Example fix
// before
if historical_futures_data_df.index.levshape[0] != 3:
raise RegressionTestException(f"...but got {historical_futures_data_df.index.levshape[1]}")
// after - print the correct level
if historical_futures_data_df.index.levshape[0] != 3:
raise RegressionTestException(f"...but got {historical_futures_data_df.index.levshape[0]}") Defensive patterns
Strategy: validation
Validate before calling
# Validate the multi-index shape before asserting
df = self.history(FutureUniverse, future, 3, flatten=True)
if len(df.index.levels[0]) != 3:
self.debug(f"History returned {len(df.index.levels[0])} chains; levshape={df.index.levshape}") Type guard
def history_has_n_chains(df, n: int) -> bool:
return len(df.index.levels) > 0 and len(df.index.levels[0]) == n Prevention
- Print df.index.levshape before trusting the message text (it references the wrong level).
- Ensure the date window / bar count yields the expected number of chains.
- Keep flatten=True consistent with the index-arity assumptions.
- Re-verify after engine upgrades that FutureUniverse history layout is unchanged.
When it happens
Trigger: Asking for 3 bars but the data only spans fewer distinct trading days (start/end date too narrow); FutureUniverse history not materialising a multi-index when fewer chains are returned; flatten=True changing the index arity unexpectedly.
Common situations: set_start_date == set_end_date so only one chain is available; data provider returning empty/short history for the requested symbol; engine changes to FutureUniverse history serialization altering the index layout.
Related errors
- Expected {expected_chain_count} futures in chain on {date},
- Expected symbol {expected_symbol} at index {i} on {date}, b
- [{UtcTime}] We hold a delisted securities: {string.Join(",",
- Expected at least two future contracts with option chains, b
- The Exchange hours was closed, verify 'extended_market_hours
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/55c8d278e8072062.
Report an issue: GitHub.