QuantConnect/Lean · error · RegressionTestException

Unexpected universe data receieved

Error message

Unexpected universe data receieved

What it means

For each of the 3 universe-history rows, the algorithm casts the single entry to StockDataSource and asserts its Symbols list has exactly 5 entries. A failure means a row in the Dropbox CSV has fewer or more than 5 symbol columns, or Reader mis-parsed the line.

Source

Thrown at Algorithm.CSharp/DropboxBaseDataUniverseSelectionAlgorithm.cs:71

            SetEndDate(2018, 07, 04);

            var universe = AddUniverse<StockDataSource>(stockDataSource =>
            {
                return stockDataSource.OfType<StockDataSource>().SelectMany(x => x.Symbols);
            });

            var historicalSelectionData = History(universe, 3).ToList();
            if (historicalSelectionData.Count != 3)
            {
                throw new RegressionTestException($"Unexpected universe data count {historicalSelectionData.Count}");
            }

            foreach (var universeData in historicalSelectionData)
            {
                var stockDataSource = (StockDataSource)universeData.Single();
                if (stockDataSource.Symbols.Count != 5)
                {
                    throw new RegressionTestException($"Unexpected universe data receieved");
                }
            }
        }

        /// <summary>
        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
        /// </summary>
        /// <code>
        /// TradeBars bars = slice.Bars;
        /// Ticks ticks = slice.Ticks;
        /// TradeBar spy = slice["SPY"];
        /// List{Tick} aaplTicks = slice["AAPL"]
        /// Quandl oil = slice["OIL"]
        /// dynamic anySymbol = slice[symbol];
        /// DataDictionary{Quandl} allQuandlData = slice.Get{Quand}
        /// Quandl oil = slice.Get{Quandl}("OIL")
        /// </code>
        /// <param name="slice">The current slice of data keyed by symbol string</param>

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Download the CSV and verify every row has exactly 5 symbol columns after the date.
  2. Log csv.Count inside Reader to catch trailing-comma or short-row issues.
  3. Filter empty strings from csv.Skip(1) before AddRange to handle trailing commas.
  4. Pin the CSV to a known-good version or vendor it locally for the regression.

Example fix

// before
stocks.Symbols.AddRange(csv.Skip(1));

// after — filter empties from trailing commas
stocks.Symbols.AddRange(csv.Skip(1).Where(s => !string.IsNullOrWhiteSpace(s)));
Defensive patterns

Strategy: validation

Validate before calling

public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
    var csv = line.ToCsv();
    var stocks = new StockDataSource { Symbol = config.Symbol };
    stocks.Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null);
    stocks.Symbols.AddRange(csv.Skip(1).Where(s => !string.IsNullOrWhiteSpace(s)));
    if (stocks.Symbols.Count != 5)
        Debug($"Row has {stocks.Symbols.Count} symbols, expected 5: {line}");
    return stocks;
}

Prevention

When it happens

Trigger: A CSV row in daily-stock-picker-backtest.csv has !=5 symbols after the date column, or the live/backtest format branch in Reader (which uses csv.Skip(1)) includes/excludes an unexpected column.

Common situations: The Dropbox CSV format changed (added/removed a symbol column), a trailing comma creating an empty extra symbol, or the isLiveMode branch being taken unexpectedly.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/9f472ef806245abf. Report an issue: GitHub.