{"record":{"id":"a8bbdd40b9e20883","repo":"ZhuLinsen/daily_stock_analysis","slug":"baostock-stock-code","errorCode":null,"errorMessage":"Baostock 未查询到 {stock_code} 的数据","messagePattern":"Baostock 未查询到 (.+?) 的数据","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"warning","filePath":"data_provider/baostock_fetcher.py","lineNumber":244,"sourceCode":"                rs = bs.query_history_k_data_plus(\n                    code=bs_code,\n                    fields=\"date,open,high,low,close,volume,amount,pctChg\",\n                    start_date=start_date,\n                    end_date=end_date,\n                    frequency=\"d\",  # 日线\n                    adjustflag=\"2\"  # 前复权\n                )\n                \n                if rs.error_code != '0':\n                    raise DataFetchError(f\"Baostock 查询失败: {rs.error_msg}\")\n                \n                # 转换为 DataFrame\n                data_list = []\n                while rs.next():\n                    data_list.append(rs.get_row_data())\n                \n                if not data_list:\n                    raise DataFetchError(f\"Baostock 未查询到 {stock_code} 的数据\")\n                \n                df = pd.DataFrame(data_list, columns=rs.fields)\n                \n                return df\n                \n            except Exception as e:\n                if isinstance(e, DataFetchError):\n                    raise\n                raise DataFetchError(f\"Baostock 获取数据失败: {e}\") from e\n    \n    def _normalize_data(self, df: pd.DataFrame, stock_code: str) -> pd.DataFrame:\n        \"\"\"\n        标准化 Baostock 数据\n        \n        Baostock 返回的列名：\n        date, open, high, low, close, volume, amount, pctChg\n        \n        需要映射到标准列名：","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/baostock_fetcher.py#L226-L262","documentation":"A DataFetchError raised when bs.query_history_k_data_plus succeeds (error_code '0') but iterating rs.next() yields zero rows. The query was valid but returned an empty set: no trading data for that code in the given window. Distinct from a query failure (error 137) — here baostock explicitly confirmed success with no data.","triggerScenarios":"Date range covering only non-trading days (holidays, weekends) for a valid code; a suspended stock with no trades in the window; a valid-prefix but nonexistent code (baostock returns empty rather than an error); start_date after the stock's listing date window or a future-dated range.","commonSituations":"Chinese New Year / National Day holiday windows returning empty; newly listed codes queried before IPO date; code typos that still convert to a well-formed sh./sz. code (e.g. 'sh.600520' that doesn't exist); delisted symbols.","solutions":["Check the date range covers at least one A-share trading day (avoid CN holidays/weekends).","Verify the code exists and trades in that window (cross-check on Akshare/East Money).","If empty windows are expected, treat this as a skip signal and catch it rather than failing the batch.","Widen or shift the range slightly for suspended stocks."],"exampleFix":"# before\ntry:\n    df = baostock_fetcher.fetch(code, '2025-10-01', '2025-10-08')  # CN holiday week\nexcept DataFetchError:\n    raise  # job aborts\n\n# after\ntry:\n    df = baostock_fetcher.fetch(code, '2025-10-01', '2025-10-08')\nexcept DataFetchError as e:\n    if '未查询到' in str(e):\n        df = pd.DataFrame()  # expected: holiday window, skip\n    else:\n        raise","handlingStrategy":"validation","validationCode":"from datetime import date\n# ensure the window contains at least one weekday outside major CN holidays\nassert any(date.fromordinal(d).weekday() < 4 for d in range(date.fromisoformat(start_date).toordinal(), date.fromisoformat(end_date).toordinal() + 1))","typeGuard":null,"tryCatchPattern":"try:\n    df = baostock_fetcher.fetch(code, start, end)\nexcept DataFetchError as e:\n    if '未查询到' in str(e):\n        df = pd.DataFrame()  # expected for holiday-only windows / suspended stocks\n    else:\n        raise","preventionTips":["Check windows against the Chinese trading calendar before querying.","Verify the code is listed and not suspended for the window (cross-check one symbol on Akshare).","Treat '未查询到' as empty-result, not error, in batch pipelines."],"tags":["baostock","empty-data","trading-calendar","a-shares"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}