fix: decide reference percent-vs-fraction scale per column, not table-wide - #532
Merged
yakew7 merged 1 commit intoSep 9, 2026
Merged
Conversation
…-wide parse_reference (and its JS twin parseReference) picked one global scale for the whole reference file: "if any value exceeds 1.5, read the whole table as percentages". A reference file assembled from multiple sources (one column already in fractions, another in percentages) then got the wrong scale applied to whichever column didn't trip the heuristic - e.g. a `race` column given as 70/20/10 forced scale=100 onto a `sex` column's already-correct 0.6/0.4, turning it into 0.006/0.004 and producing nonsense deviation numbers with no warning. The scale is now decided per column (rows grouped by the `column` identifier). Single-convention files are unaffected. Updated in both engines plus SPEC.md section 9. Closes yakew7#513 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
|
@propcgamer20-png is attempting to deploy a commit to the yashkewlani2020-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
faircode/profiler.py'sparse_reference(and the JS twinparseReferenceinassets/profiler-engine.js) made the percent-vs-fraction decision once, globally, across the entire reference file:A reference file assembled from multiple sources - one column already given as fractions, another as percentages - gets the wrong scale applied to whichever column didn't trigger the heuristic.
Repro (before)
ref_mixed.csvwithsexas fractions andraceas percentages:race's70trips the1.5threshold, soscale = 100is applied table-wide, dividingsex's correct0.6/0.4down to0.006/0.004. Thesexreference comparison becomes nonsense (0.4-0.6% expected vs 50% actual).Fix
Group rows by the
columnidentifier and decide the scale per column:Same change mirrored in
assets/profiler-engine.js(Python/JS parity), andSPEC.mdsection 9 updated. Single-convention files parse exactly as before.After
parse_reference(ref_mixed)->{"sex": {"Female": 0.6, "Male": 0.4}, "race": {"White": 0.7, "Black": 0.2, "Other": 0.1}}Tests
test_parse_reference_mixed_scale_is_decided_per_column(test_profiler.py)test_python_js_parse_reference_mixed_scale_parity(test_js_parity.py) - runsparseReferenceunder Node and asserts byte-identical result to the Python enginepytest tests/test_profiler.py tests/test_js_parity.py-> 61 passed, 1 failed. The failure (test_python_js_profiler_parity_sniffs_quoted_newlines) is pre-existing onmainon this platform and unrelated.ruffclean.Closes #513
🤖 Generated with Claude Code