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

Đang mở Phù hợp với người mới
#907 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@L4XB đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #908 của @L4XB — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sqlite
Lĩnh vực
cli, data

Hướng nghiên cứu

Tìm rows_from_file() và tái hiện các trường hợp CSV một cột bằng các lệnh sqlite-utils memory được hiển thị trong issue. Kiểm tra cách phát hiện dấu phân cách, sau đó chạy các bài kiểm thử hiện có liên quan và bổ sung kiểm thử cho đầu vào CSV một cột có tiêu đề và URL. Công việc hoàn tất khi các tệp không có dấu phân cách được nhận dạng được nhập thành một cột, trong khi hành vi của insert --sniff không thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.2k
Fork
215
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của simonw/sqlite-utils

Tất cả issue của simonw/sqlite-utils

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.