Detect CSV/TSV column types by default (#683)

The `--detect-types` option is now automatically turned on for all commands that deal with CSV or CSV.

A new `--no-detect-types` option can be used to have all columns treated as text.

Closes #679
This commit is contained in:
Simon Willison 2025-11-23 22:23:15 -08:00 committed by GitHub
commit 35377a874b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 138 additions and 48 deletions

View file

@ -227,7 +227,7 @@ def test_insert_csv_tsv(content, options, db_path, tmpdir):
fp.write(content)
result = CliRunner().invoke(
cli.cli,
["insert", db_path, "data", file_path] + options,
["insert", db_path, "data", file_path] + options + ["--no-detect-types"],
catch_exceptions=False,
)
assert result.exit_code == 0
@ -236,7 +236,7 @@ def test_insert_csv_tsv(content, options, db_path, tmpdir):
@pytest.mark.parametrize("empty_null", (True, False))
def test_insert_csv_empty_null(db_path, empty_null):
options = ["--csv"]
options = ["--csv", "--no-detect-types"]
if empty_null:
options.append("--empty-null")
result = CliRunner().invoke(
@ -430,7 +430,7 @@ def test_insert_text(db_path):
"options,input",
(
([], '[{"id": "1", "name": "Bob"}, {"id": "2", "name": "Cat"}]'),
(["--csv"], "id,name\n1,Bob\n2,Cat"),
(["--csv", "--no-detect-types"], "id,name\n1,Bob\n2,Cat"),
(["--nl"], '{"id": "1", "name": "Bob"}\n{"id": "2", "name": "Cat"}'),
),
)