fix(salary): skip Excel logical cells instead of importing them as numbers (#664)

* fix(salary): skip Excel logical cells instead of importing numbers

* test: skip Excel CLI case when openpyxl is unavailable

* changelog: place the #664 entry under [Unreleased]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Mads Lorentzen <madslorentzen_17@hotmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-20 21:02:24 +02:00
1 parent 2aadb070f4
commit 4339153f8f
3 files changed
+62

No files matched your search

+55
View File
@@ -1,8 +1,18 @@
import io
import json
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
from contextlib import redirect_stderr
from types import SimpleNamespace
try:
import openpyxl
except ImportError:
openpyxl = None
from salary_lookup import format_entry
from tools.convert_salary_excel import (
INDEX_PATTERNS,
@@ -32,6 +42,51 @@ class FakeWorksheet:
return [SimpleNamespace(value=value) for value in self.rows[row_number - 1]]
@unittest.skipUnless(openpyxl is not None, "openpyxl is not installed")
class BooleanCellCliTests(unittest.TestCase):
def test_excel_logical_cells_are_not_salary_numbers(self):
# Exercise the documented converter CLI with actual Excel boolean cells,
# including partial pairs and numeric 0/1 controls.
with tempfile.TemporaryDirectory() as tmp:
source = Path(tmp) / "salary.xlsx"
target = Path(tmp) / "salary.json"
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.append(["Company", "City", "Count", "Index", "Verified"])
sheet.append(["Logical Pair", "Berlin", True, False, True])
sheet.append(["Logical Count", "Berlin", False, 108.5, False])
sheet.append(["Logical Index", "Berlin", 12, True, None])
sheet.append(["Numeric Values", "Berlin", 0, 1, 0])
sheet.append(["Numeric Count", "Berlin", 1, 0, 1])
workbook.save(source)
workbook.close()
result = subprocess.run(
[sys.executable, str(Path(__file__).resolve().parents[1] /
"tools/convert_salary_excel.py"),
str(source), "--output", str(target)],
capture_output=True, text=True,
)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
companies = json.loads(target.read_text(encoding="utf-8"))["companies"]
self.assertEqual(companies[0]["categories"], {})
self.assertEqual(companies[1]["categories"], {
"all_employees": {"count": None, "index": 108.5},
})
self.assertEqual(companies[2]["categories"], {
"all_employees": {"count": 12, "index": None},
})
self.assertEqual(companies[3]["categories"], {
"all_employees": {"count": 0, "index": 1.0},
"verified": {"index": 0.0},
})
self.assertEqual(companies[4]["categories"], {
"all_employees": {"count": 1, "index": 0.0},
"verified": {"index": 1.0},
})
class DetectColumnTypeTests(unittest.TestCase):
def test_index_headers_are_not_misclassified_as_count(self):
for header in ("Index", "Salary Index", "Engineering Index", "Median salary"):