Skip to content

Commit 51f4354

Browse files
committed
fix(ingest): typed _detect_headers return + gpu in workflow choices
- wikitable._detect_headers returns ``tuple[int, dict[int, str]] | None`` instead of an ad-hoc ``dict[object, object]`` that mixed int column keys with a sentinel string key, which strict mypy rejected. - weekly-ingest workflow_dispatch ``category`` input now accepts ``gpu``.
1 parent 7059e02 commit 51f4354

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

.github/workflows/weekly-ingest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
category:
1111
description: "Category to ingest"
1212
type: choice
13-
options: [cpu]
13+
options: [cpu, gpu]
1414
default: cpu
1515
limit:
1616
description: "Max candidates per source"

app/ingest/sources/wikitable.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ def parse_table(table: Tag, header_rules: dict[str, list[str]]) -> Iterator[Grid
3737
grid = _table_to_grid(table)
3838
if not grid:
3939
return
40-
headers = _detect_headers(grid, header_rules)
41-
if not headers:
40+
detected = _detect_headers(grid, header_rules)
41+
if detected is None:
4242
return
43-
header_row_idx = headers["__row_index__"]
44-
column_to_field = {
45-
col: field for col, field in headers.items() if isinstance(col, int)
46-
}
43+
header_row_idx, column_to_field = detected
4744
for row_idx, row in enumerate(grid):
4845
if row_idx <= header_row_idx:
4946
continue
@@ -96,17 +93,17 @@ def _table_to_grid(table: Tag) -> list[list[str]]:
9693

9794
def _detect_headers(
9895
grid: list[list[str]], header_rules: dict[str, list[str]]
99-
) -> dict[object, object]:
100-
"""Return ``{col_idx: field_name, "__row_index__": row_idx}`` or ``{}``."""
96+
) -> tuple[int, dict[int, str]] | None:
97+
"""Return ``(row_index, {col_idx: field_name})`` or ``None`` if no header row."""
10198
for row_idx, row in enumerate(grid):
10299
mapping: dict[int, str] = {}
103100
for col_idx, text in enumerate(row):
104101
field = _match_header(text.lower(), header_rules)
105102
if field is not None:
106103
mapping.setdefault(col_idx, field)
107104
if mapping and "model" in mapping.values():
108-
return {**mapping, "__row_index__": row_idx}
109-
return {}
105+
return row_idx, mapping
106+
return None
110107

111108

112109
def _match_header(text: str, rules: dict[str, list[str]]) -> str | None:

0 commit comments

Comments
 (0)