Skip to content

fix: stop rendering "-0.0 pp" for tiny negative share changes in compare - #529

Merged
yakew7 merged 1 commit into
yakew7:mainfrom
propcgamer20-png:fix/report-negative-zero-pp
Sep 9, 2026
Merged

fix: stop rendering "-0.0 pp" for tiny negative share changes in compare#529
yakew7 merged 1 commit into
yakew7:mainfrom
propcgamer20-png:fix/report-negative-zero-pp

Conversation

@propcgamer20-png

Copy link
Copy Markdown
Collaborator

Problem

faircode/report.py renders a misleading -0.0 pp whenever a share_delta is a tiny negative float that rounds to 0.0 at one decimal place. Both surfaces are affected:

  • compare_to_terminal - the {g['share_delta'] * 100:+5.1f} column
  • compare_to_html's signed() helper - prefix = "+" if val > 0 else "" then f"{val:.1f}"

Repro (before)

$ python3 -m faircode compare a.csv b.csv
  female              50.0% ->  50.0%  ( -0.0 pp)
  male                50.0% ->  50.0%  ( +0.0 pp)

-0.0 pp next to 50.0% -> 50.0% reads as a rendering bug.

Fix

New module-level helper:

def _strip_neg_zero(val: float, dp: int = 1) -> float:
    return 0.0 if round(val, dp) == 0 else val

Applied in compare_to_terminal (share_delta column) and in signed() (so the HTML share-delta and score-delta paths are both covered). Non-zero values are untouched, so no other output changes.

After

  female              50.0% ->  50.0%  ( +0.0 pp)
  male                50.0% ->  50.0%  ( +0.0 pp)

Test

test_compare_does_not_render_negative_zero_share_delta - asserts -0.0 pp appears in neither compare_to_terminal nor compare_to_html for a dimension whose group share moves by -0.0001.

pytest tests/test_report.py tests/test_compare.py -> 39 passed. ruff clean.

Closes #515

🤖 Generated with Claude Code

A share_delta that rounds to 0.0 at one decimal place still carried its
sign through Python's %+.1f formatting, so compare output printed
"-0.0 pp" next to two identical-looking percentages (e.g. 50.0% -> 50.0%).

Added a small _strip_neg_zero() helper that returns 0.0 when a value
rounds to zero at the display precision, and applied it in both
compare_to_terminal (the share_delta column) and compare_to_html's
signed() helper (which also covers the score-delta rendering).

Closes yakew7#515

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown
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.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

@yakew7 @ahmdkaml - new PR touching a path you own, please review.

@yakew7
yakew7 merged commit dd37994 into yakew7:main Sep 9, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

report.py renders "-0.0 pp" for a tiny negative share change, in both terminal and HTML compare output

2 participants