Fix c19 delimiter fallback in tail_threshold_v2 reader
Browse files
evaluation/tail/tail_threshold_code_v2/src/eval/tail_threshold_v2/runner.py
CHANGED
|
@@ -139,6 +139,12 @@ def _sniff_delimiter(path: Path) -> str:
|
|
| 139 |
|
| 140 |
def _read_csv_rows(path: Path) -> tuple[list[str], list[dict[str, str]]]:
|
| 141 |
delimiter = _sniff_delimiter(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
with path.open("r", encoding="utf-8-sig", newline="") as handle:
|
| 143 |
reader = csv.DictReader(handle, delimiter=delimiter)
|
| 144 |
rows = [dict(row) for row in reader]
|
|
|
|
| 139 |
|
| 140 |
def _read_csv_rows(path: Path) -> tuple[list[str], list[dict[str, str]]]:
|
| 141 |
delimiter = _sniff_delimiter(path)
|
| 142 |
+
with path.open("r", encoding="utf-8-sig", newline="") as handle:
|
| 143 |
+
first_line = handle.readline()
|
| 144 |
+
# Some quoted comma CSVs with long text fields can be mis-sniffed as pipe.
|
| 145 |
+
# If there are commas in the header line but no pipes, prefer comma parsing.
|
| 146 |
+
if delimiter == "|" and "," in first_line and "|" not in first_line:
|
| 147 |
+
delimiter = ","
|
| 148 |
with path.open("r", encoding="utf-8-sig", newline="") as handle:
|
| 149 |
reader = csv.DictReader(handle, delimiter=delimiter)
|
| 150 |
rows = [dict(row) for row in reader]
|