{"record":{"id":"55c9daaee196c03e","repo":"QuantConnect/Lean","slug":"expected-but-received","errorCode":null,"errorMessage":"{} expected {}, but received {}","messagePattern":"(.+?) expected (.+?), but received (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoryAlgorithm.py","lineNumber":138,"sourceCode":"        custom_data_spyvalues = all_custom_data.loc[\"IBM\"][\"value\"]\n        self.assert_history_count(\"all_custom_data.loc[\\\"IBM\\\"][\\\"value\\\"]\", custom_data_spyvalues, 250)\n        for value in custom_data_spyvalues:\n            # do something with 'IBM.custom_data_equity' value data\n            pass\n\n    def on_data(self, data):\n        '''on_data event is the primary entry point for your algorithm. Each new data point will be pumped in here.\n\n        Arguments:\n            data: Slice object keyed by symbol containing the stock data\n        '''\n        if not self.portfolio.invested:\n            self.set_holdings(\"SPY\", 1)\n\n    def assert_history_count(self, method_call, trade_bar_history, expected):\n        count = len(trade_bar_history.index)\n        if count != expected:\n            raise AssertionError(\"{} expected {}, but received {}\".format(method_call, expected, count))\n\n\nclass CustomDataEquity(PythonData):\n    def get_source(self, config, date, is_live):\n        zip_file_name = LeanData.generate_zip_file_name(config.Symbol, date, config.Resolution, config.TickType)\n        source = Globals.data_folder + \"/equity/usa/daily/\" + zip_file_name\n        return SubscriptionDataSource(source)\n\n    def reader(self, config, line, date, is_live):\n        if line == None:\n            return None\n\n        custom_data = CustomDataEquity()\n        custom_data.symbol = config.symbol\n\n        csv = line.split(\",\")\n        custom_data.time = datetime.strptime(csv[0], '%Y%m%d %H:%M')\n        custom_data.end_time = custom_data.time + timedelta(days=1)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoryAlgorithm.py#L120-L156","documentation":"assert_history_count in HistoryAlgorithm compares the number of bars returned by a History() request against an expected count. A mismatch means the history provider returned a different number of data points than the test was baselined against, indicating a data, resolution, or history-provider regression.","triggerScenarios":"len(trade_bar_history.index) != expected after a self.history(...) call that the test invokes via assert_history_count(method_call, history, expected).","commonSituations":"History provider (SubscriptionDataReaderHistoryProvider / SynchronizingHistoryProvider) change; data file changes/additions/removals in the data folder; resolution or fillForward behavior change; the requested period or symbol changed.","solutions":["Confirm the symbol, resolution, and period passed to history() are unchanged.","Inspect the underlying data files for the symbol/date range; added or removed bars change the count.","Trace the history provider pipeline for fillForward/exchange-hours filtering changes that add or drop bars.","If the new count is correct, update the expected value passed to assert_history_count and document why."],"exampleFix":"# before\nself.assert_history_count('History<TradeBar>(SPY, 10, daily)', history, 10)\n# after: expected recalculated after a data correction\nself.assert_history_count('History<TradeBar>(SPY, 10, daily)', history, 9)","handlingStrategy":"validation","validationCode":"# wrap history calls with a count guard helper\ndef safe_history(algo, *args, expected=None, **kwargs):\n    h = algo.history(*args, **kwargs)\n    if expected is not None and len(h.index) != expected:\n        algo.debug(f\"history count {len(h.index)} != expected {expected}\")\n    return h","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat expected history counts as baselines that must be updated alongside data/engine changes.","Log the actual count on mismatch before failing, to speed diagnosis.","Pin symbol, resolution, and period in helper methods to avoid drift."],"tags":["quantconnect","lean","regression","history","trade-bars","data-provider"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}