mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
fix(salary): detect company column from header token, not exact match (#151)
convert_salary_excel.py detected the company column via exact membership in COMPANY_PATTERNS, so common real-world headers like "Company Name" or "Employer Name" were never matched. parse_sheet then returned [] for that sheet, silently dropping it from salary_data.json (or exiting with no output for a single-sheet file). Route company-column detection through the existing header_matches() token matcher (already used for count/index detection). This only adds detections; inputs that already worked (bare "Company"/"Firma"/...) are unaffected. Adds a regression test in tests/test_convert_salary_excel.py that fails on master (returns []) and passes after the fix.
This commit is contained in:
@@ -87,6 +87,23 @@ class DetectColumnTypeTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(companies[0]["categories"]["software_engineering"], {"count": 8, "index": 110.0})
|
self.assertEqual(companies[0]["categories"]["software_engineering"], {"count": 8, "index": 110.0})
|
||||||
|
|
||||||
|
def test_parse_sheet_detects_company_column_with_token_header(self):
|
||||||
|
# Real-world salary sheets rarely use the bare token "Company";
|
||||||
|
# headers like "Company Name" / "Employer Name" must still be
|
||||||
|
# detected as the company column (previously silently skipped -> []).
|
||||||
|
for header in ("Company", "Company Name", "Employer Name"):
|
||||||
|
with self.subTest(header=header):
|
||||||
|
ws = FakeWorksheet([
|
||||||
|
(header, "Salary"),
|
||||||
|
("Example Corp", 105.5),
|
||||||
|
])
|
||||||
|
companies = parse_sheet(ws)
|
||||||
|
self.assertEqual(len(companies), 1)
|
||||||
|
self.assertEqual(companies[0]["company"], "Example Corp")
|
||||||
|
self.assertEqual(
|
||||||
|
companies[0]["categories"]["salary"], {"index": 105.5}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ def parse_sheet(ws, sheet_label=None):
|
|||||||
header_row = None
|
header_row = None
|
||||||
for row_idx, row in enumerate(ws.iter_rows(min_row=1, max_row=10, values_only=False), start=1):
|
for row_idx, row in enumerate(ws.iter_rows(min_row=1, max_row=10, values_only=False), start=1):
|
||||||
for cell in row:
|
for cell in row:
|
||||||
if cell.value and str(cell.value).strip().lower() in COMPANY_PATTERNS:
|
if cell.value and header_matches(str(cell.value), COMPANY_PATTERNS):
|
||||||
header_row = row_idx
|
header_row = row_idx
|
||||||
break
|
break
|
||||||
if header_row:
|
if header_row:
|
||||||
@@ -111,7 +111,7 @@ def parse_sheet(ws, sheet_label=None):
|
|||||||
city_col = None
|
city_col = None
|
||||||
for i, h in enumerate(headers):
|
for i, h in enumerate(headers):
|
||||||
h_lower = h.lower()
|
h_lower = h.lower()
|
||||||
if h_lower in COMPANY_PATTERNS:
|
if header_matches(h, COMPANY_PATTERNS):
|
||||||
company_col = i
|
company_col = i
|
||||||
elif h_lower in CITY_PATTERNS:
|
elif h_lower in CITY_PATTERNS:
|
||||||
city_col = i
|
city_col = i
|
||||||
|
|||||||
Reference in New Issue
Block a user