Util weight#940
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## #932_triangle_weight #940 +/- ##
========================================================
+ Coverage 88.30% 88.53% +0.22%
========================================================
Files 88 89 +1
Lines 5029 5189 +160
Branches 642 658 +16
========================================================
+ Hits 4441 4594 +153
+ Misses 443 442 -1
- Partials 145 153 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ca2f50d. Configure here.
| if hasattr(X, "w_"): | ||
| self.w_ = self._set_weight_func( | ||
| X=X * X.w_, | ||
| ) |
There was a problem hiding this comment.
Prior weights use wrong attribute
Medium Severity
When prior weights exist, TriangleWeight.fit multiplies the input triangle by X.w_ and passes that triangle into _set_weight_func. Development.fit instead checks w_v2_ and combines prior weights on obj.age_to_age. After Development, w_ and w_v2_ can differ, so chained weighting no longer matches development’s v2 path.
Reviewed by Cursor Bugbot for commit ca2f50d. Configure here.
| else: | ||
| self.w_ = self._set_weight_func( | ||
| X=X, | ||
| ) |
There was a problem hiding this comment.
Ratio drops need age-to-age
Medium Severity
TriangleWeight.fit feeds the caller’s triangle straight into _set_weight_func, so _drop_x_func and _drop_n_func rank and threshold X.values as given. Those steps expect age-to-age link ratios; Development always builds v2 weights from obj.age_to_age. The same cumulative triangle passed to Development.fit can get incorrect exclusions here.
Reviewed by Cursor Bugbot for commit ca2f50d. Configure here.


Summary of Changes
Related GitHub Issue(s)
Additional Context for Reviewers
uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)Note
Medium Risk
New public API and ~500 lines of weight logic that must stay consistent with
Development; wrong ordering or preserve behavior would change LDFs once integrated, though productionDevelopmentpaths are unchanged in this diff.Overview
Introduces
TriangleWeight, a new sklearn-style utility that builds a weight triangle from the same exclusion knobs asDevelopment(n_periods,drop,drop_valuation,drop_above/drop_below,drop_high/drop_low,preserve). It is exported fromchainladder.utilsand the top-levelchainladderpackage, withEXPECTED_PUBLIC_APIupdated accordingly.The implementation lives in
chainladder/utils/triangle_weight.pyand documents a different drop order thanDevelopment: threshold drops (drop_above/drop_below) run before rank-baseddrop_high/drop_low(the docstring notes steps 4 and 5 are reversed relative toDevelopment).fit/transformsetw_on triangles and can compose with existingw_weights.Tests in
test_development.pyare expanded with_FutureDevelopment, aTriangleWeightsubclass that recomputes LDFs via weighted regression, and assertions that its LDFs matchDevelopmentacross drop scenarios—exercising the new utility without wiring it intoDevelopmentyet.Reviewed by Cursor Bugbot for commit 60cabb2. Bugbot is set up for automated code reviews on this repo. Configure here.