mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-24 10:17:05 +02:00
Read a single-column CSV file as one column when detecting the format
rows_from_file() sniffed the CSV dialect with no delimiters= list, so
csv.Sniffer considered every character. A single-column file then either
had no consistent candidate (csv.Error: Could not determine delimiter) or
was split on a letter that repeats on each line: a column of URLs came out
as {"ur": "https://examp", "": "e.com/a"}.
Format detection now sniffs for a comma, a semicolon, a tab or a pipe,
and reads a file with none of them as plain CSV.
Closes #907
This commit is contained in:
parent
9c66bafa52
commit
bb93d57055
3 changed files with 45 additions and 1 deletions
|
|
@ -157,6 +157,17 @@ def test_memory_csv_encoding(tmpdir, use_stdin):
|
|||
}
|
||||
|
||||
|
||||
def test_memory_csv_single_column(tmpdir):
|
||||
csv_path = str(tmpdir / "names.csv")
|
||||
with open(csv_path, "w") as fp:
|
||||
fp.write("name\nAnn\nBob\n")
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["memory", csv_path, "select * from names", "--nl"]
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
assert result.output.strip() == '{"name": "Ann"}\n{"name": "Bob"}'
|
||||
|
||||
|
||||
def test_memory_csv_headers_only(tmpdir):
|
||||
csv_path = str(tmpdir / "headers_only.csv")
|
||||
with open(csv_path, "w") as fp:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue