Skip to content

Label ProportionShift top bars with system names (#47) - #48

Open
andyreagan wants to merge 2 commits into
masterfrom
fix/issue-47-proportionshift-system-names
Open

Label ProportionShift top bars with system names (#47)#48
andyreagan wants to merge 2 commits into
masterfrom
fix/issue-47-proportionshift-system-names

Conversation

@andyreagan

@andyreagan andyreagan commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #47.

Problem

ProportionShift.get_shift_graph leaves the cumulative bars at the top of the plot unlabeled, unlike the JSD shift graph where each system's name is written next to its purple/orange bar. As the issue reporter found, adding all_pos_contributions=True (the difference from the JSD definition) does add the names but breaks the plot by pushing every bar to the right-hand side.

Cause

all_pos_contributions conflates two things in the plotting layer:

  1. Bar direction — in get_bar_dims, it flips a type's bar based on the sign of p_diff. This is correct for JSD, whose contributions are inherently non-negative. But proportion shift scores already carry their sign (positive when a type is more prevalent in system 2, negative for system 1), so flipping forces every bar positive → all bars point right.
  2. Top-bar labels — only the all_pos_* bar order uses the system names as symbols; the neg_total/pos_total bars used by ProportionShift have empty symbols.

So the reporter's workaround couldn't win: getting the labels also flipped the bars.

Fix

Separate the two concerns. Add a label_total_with_system_names plot param that labels the neg_total/pos_total bars with the system names without changing bar direction, and enable it for ProportionShift. Those bars already share the same purple/orange colors as the JSD all_pos_* bars, so the result visually matches the JSD graph.

  • shifterator/plotting.py: new label_total_with_system_names param (default False); when set, the neg_total/pos_total symbols become the system names.
  • shifterator/shifts.py: ProportionShift.get_shift_graph opts in via kwargs.setdefault(...) so callers can still override.

Tests

Added TestIssue47ProportionShiftSystemNames in tests/test_issues.py:

  • system names appear on the graph (custom and default names)
  • bars remain two-sided (regression guard against the all-right-side breakage)
  • other shift types are unaffected

Full suite: 80 passed locally (uv run pytest).

Note

This PR also bumps the version to 0.5.1 and exposes shifterator.__version__, so a branch install can be confirmed with import shifterator; print(shifterator.__version__).

andyreagan and others added 2 commits June 30, 2026 10:22
ProportionShift's cumulative top bars were unlabeled, unlike the JSD
shift graph which names each system next to its colored bar. Enabling
`all_pos_contributions=True` (as suggested in the issue) added the names
but forced every bar to point right, because proportion shift scores
already carry their sign and that flag flips negatives to positive.

Add a `label_total_with_system_names` plot param that labels the
`neg_total`/`pos_total` bars with the system names without touching bar
direction, and turn it on for ProportionShift. The neg/pos total bars
already use the same purple/orange colors as the JSD bars, so the graph
now matches.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add __version__ to the package so the installed version can be checked
with `import shifterator; shifterator.__version__`, and bump to 0.5.1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andyreagan andyreagan self-assigned this Jun 30, 2026
@andyreagan andyreagan added the bug Something isn't working label Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System Names Missing from ProportionShift

1 participant