rows_from_file() splits a single-column CSV file on a letter, or raises csv.Error

未關閉 適合新手
#907 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

@L4XB 已經在處理了。

開始於 2026年10月17日。

  • #908 來自 @L4XB —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python, sqlite
領域
cli, data

研究方向

找到 rows_from_file(),並使用 issue 中顯示的 sqlite-utils memory 命令重現單欄 CSV 的情況。檢查分隔符偵測方式,然後執行相關的現有測試,並為包含標頭和 URL 的單欄 CSV 輸入新增測試涵蓋範圍。當未辨識到分隔符的檔案作為一欄匯入,且 insert --sniff 的行為維持不變時,工作即告完成。

由索引模型根據 Issue 內容生成。

描述

When rows_from_file() detects the format of a single-column CSV file, it either fails or splits the column on a letter. That affects sqlite-utils memory file.csv and any Python call that leaves format= unset.

$ printf 'name\nAnn\nBob\n' > names.csv
$ sqlite-utils memory names.csv "select * from names"
...
_csv.Error: Could not determine delimiter

$ printf 'url\nhttps://example.com/a\nhttps://example.org/b\n' > urls.csv
$ sqlite-utils memory urls.csv "select * from urls"
[{"ur": "https://examp", "": "e.com/a"},
 {"ur": "https://examp", "": "e.org/b"}]

(sqlite-utils 4.2.1)

The detection calls csv.Sniffer().sniff() on the first 2048 bytes without a delimiters= list. The sniffer then treats any character as a candidate, so a file with a single column either has no consistent candidate (csv.Error) or has a letter that happens to repeat the same number of times on every line (l above).

A fix could sniff only for the delimiters a CSV file is realistically written with (,, ;, tab, |) and read the file as one column when none of them is found. insert --sniff calls the sniffer the same way, but that is an explicit request to detect the dialect, so I would leave it unchanged.

主要語言
Python
星號
2.2k
分支
215
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

simonw/sqlite-utils 的其他 Issue

查看 simonw/sqlite-utils 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。