{"record":{"id":"6fa7eebc31f72f84","repo":"QuantConnect/Lean","slug":"spy-tick-history-is-empty","errorCode":null,"errorMessage":"SPY tick history is empty","messagePattern":"SPY tick history is empty","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm.py","lineNumber":39,"sourceCode":"class 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":21,"sourceCodeEnd":45,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/PandasDataFrameFromMultipleTickTypeTickHistoryRegressionAlgorithm.py#L21-L45","documentation":"Regression assertion that the SPY tick history dataframe returned by History is not empty. It checks history.shape[0] == 0 after a successful (non-throwing) call. An empty frame means the call succeeded but yielded zero rows — the request was valid yet no data rows were returned.","triggerScenarios":"self.history(Tick, spy, timedelta(days=1), Resolution.TICK) returns a dataframe with zero rows. This happens when the date window contains no tick data (e.g. 2013-10-08 is outside the available data range, a weekend/holiday, or the market was closed), when the symbol's tick data files are empty/missing-but-tolerated, or when filters (exchange hours, data normalization) removed all rows.","commonSituations":"The backtest date range does not overlap with on-disk tick data for SPY. A data import produced empty tick files. The start/end date fell on a non-trading day. The data reader found the config but the zip/CSV contained no rows for that day.","solutions":["Confirm on-disk tick data exists for SPY on 2013-10-08 (a trading day) and the file is non-empty.","Verify the history window (timedelta(days=1) from start date) overlaps an actual trading session with ticks.","If data is genuinely absent for that range, widen the window or pick a known-populated date rather than asserting non-empty.","Check data normalization / exchange-hour filtering is not stripping all rows."],"exampleFix":"# before\nif history.shape[0] == 0:\n    raise AssertionError(\"SPY tick history is empty\")\n\n# after (fall back to a wider window or fail with the queried range)\nif history.shape[0] == 0:\n    history = self.history(Tick, spy, timedelta(days=5), Resolution.TICK)\nif history.shape[0] == 0:\n    raise AssertionError(\n        f\"SPY tick history is empty for window starting {self.start_date}\")","handlingStrategy":"validation","validationCode":"# Check row count and widen the window if empty rather than asserting\nhistory = self.history(Tick, spy, timedelta(days=1), Resolution.TICK)\nif history.shape[0] == 0:\n    history = self.history(Tick, spy, timedelta(days=5), Resolution.TICK)\nif history.shape[0] == 0:\n    self.debug(f\"No SPY tick rows for window; data may be missing\")","typeGuard":"def history_has_rows(history):\n    \"\"\"True when the returned history frame contains at least one row.\"\"\"\n    return history is not None and history.shape[0] > 0","tryCatchPattern":null,"preventionTips":["Verify the date window overlaps an actual trading session with tick data.","Log history.shape[0] before asserting non-empty so gaps are visible.","Prefer a known-populated date range for tick-history regression tests."],"tags":["quantconnect","lean","history","tick-data","empty-data","regression-test","python"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}