mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
fix(salary): skip non-numeric and identifier columns in Excel conversion (#152)
parse_sheet treated every column that was not company/city as a salary category, with no check that the column actually held numeric salary data. This turned free-text columns (e.g. Notes) into bogus string categories and numeric identifier columns (e.g. Id) into mistaken salary indexes.
- Drop identifier headers (ID_PATTERNS = {id, personnummer}) at classification time.
- Skip non-numeric standalone values and fully-null count/index pairs at row-processing time.
- Adds regression tests (skips_free_text_column, skips_numeric_identifier_column, keeps_numeric_salary_column) that fail on master and pass after the fix.
This commit is contained in:
@@ -104,6 +104,42 @@ class DetectColumnTypeTests(unittest.TestCase):
|
||||
companies[0]["categories"]["salary"], {"index": 105.5}
|
||||
)
|
||||
|
||||
def test_skips_free_text_column(self):
|
||||
# A free-text "Notes" column must not become a bogus salary category.
|
||||
ws = FakeWorksheet([
|
||||
("Company", "Salary Index", "Notes"),
|
||||
("Example Corp", 105.5, "good"),
|
||||
])
|
||||
|
||||
companies = parse_sheet(ws)
|
||||
|
||||
self.assertIn("salary_index", companies[0]["categories"])
|
||||
self.assertNotIn("notes", companies[0]["categories"])
|
||||
|
||||
def test_skips_numeric_identifier_column(self):
|
||||
# A numeric "Id" column (employee id) must not be treated as a salary index.
|
||||
ws = FakeWorksheet([
|
||||
("Company", "Salary Index", "Id"),
|
||||
("Example Corp", 105.5, 7),
|
||||
])
|
||||
|
||||
companies = parse_sheet(ws)
|
||||
|
||||
self.assertIn("salary_index", companies[0]["categories"])
|
||||
self.assertNotIn("id", companies[0]["categories"])
|
||||
|
||||
def test_keeps_numeric_salary_column(self):
|
||||
# A genuine numeric salary column still produces a salary category.
|
||||
ws = FakeWorksheet([
|
||||
("Company", "Salary Index"),
|
||||
("Example Corp", 105.5),
|
||||
])
|
||||
|
||||
companies = parse_sheet(ws)
|
||||
|
||||
self.assertIn("salary_index", companies[0]["categories"])
|
||||
self.assertEqual(companies[0]["categories"]["salary_index"], {"index": 105.5})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user