mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-13 18:37:39 +00:00
fix(salary): split combined name-and-city workbook columns (#660)
* fix(salary): split combined name-and-city workbook columns
The IDA demonstration workbook heads its company column "Firmanavn og by"
and stores "Ørsted A/S, Fredericia" in that one cell. After the header is
detected, convert_salary_excel copied the whole cell into company with
city "". salary_lookup --city only reads entry["city"], so the documented
lookup for Ørsted in Fredericia missed.
When the company header also names a city and there is no city column,
split the cell on the last ", ". A Company-only header still keeps commas
in the name.
* fix(salary): split a combined name-and-city cell on the last comma
Real IDA cells have no space after the separating comma
("Ørsted A/S,Fredericia"), and some company names contain ", "
themselves ("Rambøll Danmark A/S, Odense,Odense C"). Splitting on the
last ", " missed almost every real row, so --city still dropped out.
split_combined_company_city now splits on the last "," and strips both
parts. Test fixtures use the real unspaced cell shape, and a new unit
test covers a company name that contains a comma. The docstrings,
CHANGELOG entry, tools/README_SALARY_TOOL.md and the README salary
section describe the new split.
* docs(changelog): move the combined-city entry under Unreleased
The merge of master brought in the 1.7.3 release section, which left
this PR's Fixed entry under an already released version. Move it to
the Unreleased Fixed list.
* chore: drop the CHANGELOG hunk, the file is frozen since #800
Release notes are generated from PR titles now.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Mads Lorentzen <madslorentzen17@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
5 files changed
+165
-3
No files matched your search
@@ -18,7 +18,9 @@ The output file (salary_data.json) will be written to the repository root.
|
||||
Expected Excel format:
|
||||
- A header row with column names
|
||||
- A "Company" or "Firma" column (required)
|
||||
- An optional "City" or "By" column
|
||||
- An optional "City" or "By" column. A combined header such as
|
||||
"Firmanavn og by" / "Company and City" (no separate city column)
|
||||
is split on the last comma, and both parts are stripped, into company and city.
|
||||
- Any number of numeric data columns (salary index, count, etc.)
|
||||
|
||||
The script auto-detects the header row and column layout. For Excel files
|
||||
@@ -97,6 +99,28 @@ def parse_numeric_cell(value):
|
||||
return _finite_float(text)
|
||||
|
||||
|
||||
def split_combined_company_city(value):
|
||||
"""Split a combined name-and-city cell on its last comma.
|
||||
|
||||
The IDA demonstration workbook heads its company column "Firmanavn og by"
|
||||
and stores "Ørsted A/S,Fredericia" (no space after the comma). salary_lookup's
|
||||
--city filter only reads entry["city"], so leaving the city in the company
|
||||
string makes the documented
|
||||
`python3 salary_lookup.py "Ørsted" --city "Fredericia"` miss. Split on the
|
||||
last comma and strip both parts: a city may contain spaces ("Kongens Lyngby")
|
||||
and a company may contain ", " ("Rambøll Danmark A/S, Odense,Odense C"
|
||||
keeps "Rambøll Danmark A/S, Odense"). A cell with no comma stays the company
|
||||
with an empty city.
|
||||
"""
|
||||
if not isinstance(value, str) or "," not in value:
|
||||
return value, ""
|
||||
company, city = value.rsplit(",", 1)
|
||||
company, city = company.strip(), city.strip()
|
||||
if company and city:
|
||||
return company, city
|
||||
return value, ""
|
||||
|
||||
|
||||
def header_matches(header, patterns):
|
||||
"""Return True when a header contains a meaningful pattern match.
|
||||
|
||||
@@ -224,6 +248,12 @@ def parse_sheet(ws, sheet_label=None):
|
||||
print(f"Warning: Could not find company column in sheet '{ws.title}'.", file=sys.stderr)
|
||||
return []
|
||||
|
||||
# "Firmanavn og by" / "Company and City": one column holds both, and there
|
||||
# is no separate city column. Split the cell so --city can see the city.
|
||||
combined_name_and_city = city_col is None and header_matches(
|
||||
headers[company_col], CITY_PATTERNS
|
||||
)
|
||||
|
||||
# Identify data columns (everything that's not company/city or an identifier)
|
||||
data_cols = []
|
||||
for i, h in enumerate(headers):
|
||||
@@ -327,6 +357,8 @@ def parse_sheet(ws, sheet_label=None):
|
||||
city_name = str(row[city_col]).strip()
|
||||
else:
|
||||
city_name = ""
|
||||
if combined_name_and_city and not city_name:
|
||||
company_name, city_name = split_combined_company_city(company_name)
|
||||
|
||||
entry = {
|
||||
"company": company_name,
|
||||
|
||||
Reference in new issue
Block a user