{"record":{"id":"3237ba6668f36d66","repo":"ZhuLinsen/daily_stock_analysis","slug":"csv","errorCode":null,"errorMessage":"CSV 解析失败：请检查分隔符是否一致、列数是否匹配。常见原因：引号未闭合、某行列数与其他行不一致。原始错误: {e}","messagePattern":"CSV 解析失败：请检查分隔符是否一致、列数是否匹配。常见原因：引号未闭合、某行列数与其他行不一致。原始错误: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/services/import_parser.py","lineNumber":214,"sourceCode":"        df = pd.DataFrame(rows)\n        first_row = [str(x).strip().lower() for x in df.iloc[0].tolist()]\n        if any(c in _CODE_ALIASES or c in _NAME_ALIASES for c in first_row):\n            df.columns = df.iloc[0]\n            df = df.iloc[1:].reset_index(drop=True)\n        return _parse_dataframe(df)\n\n    # Try pandas for CSV-like; use dtype=str to preserve leading zeros (e.g. 00700)\n    try:\n        df = pd.read_csv(io.StringIO(text), sep=None, engine=\"python\", header=None, dtype=str)\n        if df is not None and not df.empty:\n            df = df.fillna(\"\")\n            first_row = [str(x).strip().lower() for x in df.iloc[0].tolist()]\n            if any(c in _CODE_ALIASES or c in _NAME_ALIASES for c in first_row):\n                df.columns = df.iloc[0]\n                df = df.iloc[1:].reset_index(drop=True)\n            return _parse_dataframe(df)\n    except pd.errors.ParserError as e:\n        raise ValueError(\n            f\"CSV 解析失败：请检查分隔符是否一致、列数是否匹配。\"\n            f\"常见原因：引号未闭合、某行列数与其他行不一致。原始错误: {e}\"\n        ) from e\n    except Exception:\n        pass\n\n    # Fallback: plain text, split by comma/tab/space\n    lines = text.strip().splitlines()\n    rows = []\n    for line in lines:\n        line = line.strip()\n        if not line:\n            continue\n        parts = re.split(r\"[\\t,;\\s]+\", line)\n        if parts:\n            rows.append(parts)\n    if not rows:\n        return []","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/import_parser.py#L196-L232","documentation":"Raised when pandas.read_csv (sep=None, python engine, header=None, dtype=str) throws pd.errors.ParserError on the pasted/parsed text. This is a strict-failure branch: structurally malformed delimiter-separated data (ragged rows, unclosed quotes) rather than merely unusual delimiters, since sep=None auto-detects those.","triggerScenarios":"A quoted field with an unclosed quote spanning lines; rows with different column counts mid-file; embedded newlines inside quotes combined with mismatched delimiters.","commonSituations":"Hand-edited CSV where a quote was dropped; mixed delimiter files (some comma, some tab); copy-paste from Excel引入 stray quotes.","solutions":["Open the file and fix the malformed line quoted in the original error (row number is in the message)","Normalize delimiters: re-export from the source (Excel/Sheets) as clean CSV","If data is loose plain text (codes separated by spaces/tabs per line), simplify to one code per line — the single-column fast path handles it without pandas"],"exampleFix":"# before: 600519,'贵州\"茅台   <- unclosed quote\n# after:  600519,贵州茅台\n#         00700,腾讯","handlingStrategy":"fallback","validationCode":"def is_wellformed_csv(text: str) -> bool:\n    import pandas as pd, io\n    try:\n        pd.read_csv(io.StringIO(text), sep=None, engine='python', header=None, dtype=str)\n        return True\n    except pd.errors.ParserError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    items = parse_import_from_bytes(data, fn)\nexcept ValueError as e:\n    if 'CSV 解析失败' in str(e):\n        # fall back to the per-line loose split the parser itself uses downstream\n        lines = [l.strip() for l in data.decode('utf-8', 'ignore').splitlines() if l.strip()]\n        items = parse_import_from_text('\\n'.join(l.split(',')[0] for l in lines))\n    else:\n        raise","preventionTips":["Re-export from Excel/Sheets instead of hand-editing CSV","Prefer one code per line — the single-column fast path avoids pandas entirely","Check quotes balance when editing quoted fields manually"],"tags":["import","csv","pandas","parse-error"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}