Rank a contribution table over a window, not always all history - #32
Merged
Conversation
0.9.0. `contribution_table` called `expanding_pct_rank` unconditionally, so a caller could not hold it to the same stretch of weeks as the aggregate percentile it sits under. cot-analyzer's /exposure is that caller: its Lookback control moved the headline, the band and the rank scale while the contributions table beneath them stayed on all history, so the page showed "higher than 97% of the last 52 weeks" three lines above a column headed "%ile" measured against twenty years, with nothing on either saying they were different questions. The parameter belongs here rather than in the page. cot-analyzer computes no metrics of its own, and per-member ranking done there would have been the first exception to that. `window=None` is the expanding form, so every existing caller is unchanged; `windowed_pct_rank` already clamps min_periods to the window, so a 26-week window against a 104-week floor needs nothing from the caller. Two tests. The renormalisation one walks into a sign trap worth naming: commercial net is negative, so a step back toward zero ranks HIGH in notional, and the numbers read inverted for that reason rather than by mistake. Co-Authored-By: Claude Opus 5 <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.
0.9.0.
exposure.contribution_tablecalledexpanding_pct_rankunconditionally, so a caller could not hold it to the same stretch of weeks as the aggregate percentile it sits under.cot-analyzer's
/exposureis that caller. Its Lookback control moved the headline, the band and the rank scale while the contributions table beneath them stayed on all history, so on "52 weeks" the page said "higher than 97% of the last 52 weeks" three lines above a column headed "%ile" measured against twenty years, both on screen at once with nothing saying they were different questions. Live, Gold alone on 52 weeks: headline 62nd percentile, table row 99.The change
window=Noneis the expanding form, so every existing caller is unchanged, pinned by a test asserting frame equality between the bare call andwindow=None.windowed_pct_rankalready clampsmin_periodsto the window, so a 26-week window against a 104-week floor needs nothing from the caller.Why here rather than in the page
cot-analyzer computes no metrics of its own. Per-member ranking done there would have been the first exception, and the alternative considered (leave the table expanding and explain it in the copy) is not a fix: copy can describe two bases, it cannot make them comparable, and the control exists because the window is the reader's choice.
One trap in the tests
test_a_window_renormalises_where_the_expanding_form_does_notreads inverted on purpose. Commercial net is negative, so a step back toward zero ranks HIGH in notional: expanding 66.7 against windowed(3) 100.0. The comment says so, because a future reader will otherwise see it as a typo and "fix" it.Verification
389 tests pass with both stores set,
ruff check src testsclean,check_dep_floors.pyclean.Consumer
cot-analyzer's branch
claude/zealous-sutherland-b45608pinscotmetrics[options]>=0.9.0and cannot merge until this lands. That PR is itself stacked on cot-analyzer #64.🤖 Generated with Claude Code