File size: 1,567 Bytes
0be14c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""Independently re-verify this evalpack: run every gold SQL with DuckDB
against the CSVs in tables/ and compare to the expected answers.

Usage: python verify.py     (exits 1 on any mismatch)
"""
import json
import sys
from pathlib import Path

import duckdb

HERE = Path(__file__).parent
con = duckdb.connect()
for csv in sorted((HERE / "tables").glob("*.csv")):
    path = str(csv.resolve()).replace("'", "''")
    con.execute(
        'CREATE VIEW "%s" AS SELECT * FROM read_csv_auto(\'%s\')'
        % (csv.stem, path)
    )

failures = 0
total = 0
for line in (HERE / "questions.jsonl").read_text().splitlines():
    if not line.strip():
        continue
    q = json.loads(line)
    total += 1
    row = con.execute(q["gold_sql"]).fetchone()
    observed = row[0] if row else None
    expected = q["expected_answer"]
    if q["answer_type"] == "string":
        ok = str(observed) == str(expected)
    else:
        nd = q.get("round_decimals", 0)
        try:
            ok = (
                observed is not None
                and abs(round(float(observed), nd) - round(float(expected), nd))
                < 1e-9
            )
        except (TypeError, ValueError):
            ok = False
    status = "OK  " if ok else "FAIL"
    if not ok:
        failures += 1
        print(f"{status} {q['id']}: expected={expected} observed={observed}")
        print(f"     {q['gold_sql']}")
    else:
        print(f"{status} {q['id']}: {expected}")

print(f"\n{total - failures}/{total} verified exactly")
sys.exit(1 if failures else 0)