Label ProportionShift top bars with system names (#47) - #48
Open
andyreagan wants to merge 2 commits into
Open
Conversation
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>
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.
Fixes #47.
Problem
ProportionShift.get_shift_graphleaves 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, addingall_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_contributionsconflates two things in the plotting layer:get_bar_dims, it flips a type's bar based on the sign ofp_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.all_pos_*bar order uses the system names as symbols; theneg_total/pos_totalbars 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_namesplot param that labels theneg_total/pos_totalbars with the system names without changing bar direction, and enable it forProportionShift. Those bars already share the same purple/orange colors as the JSDall_pos_*bars, so the result visually matches the JSD graph.shifterator/plotting.py: newlabel_total_with_system_namesparam (defaultFalse); when set, theneg_total/pos_totalsymbols become the system names.shifterator/shifts.py:ProportionShift.get_shift_graphopts in viakwargs.setdefault(...)so callers can still override.Tests
Added
TestIssue47ProportionShiftSystemNamesintests/test_issues.py:Full suite: 80 passed locally (
uv run pytest).Note
This PR also bumps the version to
0.5.1and exposesshifterator.__version__, so a branch install can be confirmed withimport shifterator; print(shifterator.__version__).