`csv.Sniffer.sniff()` raises `Could not determine delimiter` when the sample contains a field larger than field_size_limit()
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Summary
csv.Sniffer().sniff() raises csv.Error: Could not determine delimiter for a sample whose first row contains a field longer than the current csv.field_size_limit() (131072 by default), even when every following row is consistently delimited.
Reproduction Code
import csv
sample = 'a,"' + 'x' * 200_000 + '",b\n' + 'c,d,e\n' * 50
print(csv.Sniffer().sniff(sample).delimiter)
Actual Behavior
Traceback (most recent call last):
File "repro.py", line 4, in <module>
print(csv.Sniffer().sniff(sample).delimiter)
~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "Lib/csv.py", line 384, in sniff
raise Error("Could not determine delimiter")
_csv.Error: Could not determine delimiter
Expected Behavior
sniff() should return a dialect with `delimiter=','
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-157689
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 issue 中的範例重現失敗,然後檢查 Lib/csv.py 中 Sniffer.sniff() 附近的程式碼。檢查 field_size_limit 如何影響分隔符偵測,並驗證該範例回傳的 dialect 其分隔符是逗號,同時不削弱限制行為。issue 中連結的 PR gh-157689 表示這項工作可能已經在進行中。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100