@@ -281,6 +281,43 @@ def test_python_js_reference_parity_on_unmatched_column(tmp_path):
281281 assert "reference file's column(s) don't match any profiled dimension: totally_wrong_col" in completed .stderr
282282
283283
284+ def test_python_js_parse_reference_mixed_scale_parity (tmp_path ):
285+ """parse_reference / parseReference decide percent-vs-fraction per column,
286+ not once across the whole table, so a reference file mixing conventions
287+ between columns parses identically on both engines (#513)."""
288+ from faircode .profiler import parse_reference
289+
290+ ref_df = pd .DataFrame ({
291+ "column" : ["sex" , "sex" , "race" , "race" , "race" ],
292+ "group" : ["Female" , "Male" , "White" , "Black" , "Other" ],
293+ "share" : [0.6 , 0.4 , 70 , 20 , 10 ],
294+ })
295+ py_result = parse_reference (ref_df )
296+ assert py_result == {
297+ "sex" : {"Female" : 0.6 , "Male" : 0.4 },
298+ "race" : {"White" : 0.7 , "Black" : 0.2 , "Other" : 0.1 },
299+ }
300+
301+ table_json = tmp_path / "table.json"
302+ table_json .write_text (json .dumps ({
303+ "columns" : list (ref_df .columns ),
304+ "rows" : ref_df .to_dict (orient = "records" ),
305+ }), encoding = "utf-8" )
306+
307+ script = (
308+ "const fs=require('fs');"
309+ "require(process.argv[1]);"
310+ "const t=JSON.parse(fs.readFileSync(process.argv[2],'utf-8'));"
311+ "process.stdout.write(JSON.stringify(globalThis.FairCodeProfiler.parseReference(t)));"
312+ )
313+ completed = subprocess .run (
314+ ["node" , "-e" , script ,
315+ str (REPO_ROOT / "assets" / "profiler-engine.js" ), str (table_json )],
316+ capture_output = True , text = True , encoding = "utf-8" , check = True ,
317+ )
318+ assert json .loads (completed .stdout ) == py_result
319+
320+
284321def test_python_js_json_parity_inconsistent_keys ():
285322 """Records-orient JSON where later records add columns the first one
286323 doesn't have (#144). The JS parseJSON() used to derive columns from only
0 commit comments