Repository navigation
Description
Are you on the latest chainladder version?
- Yes, this bug occurs on the latest version.
Describe the bug in words
BornhuetterFerguson, Benktander, CapeCod and ExpectedLoss expect sample_weight with one development column, such as premium.latest_diagonal. If a user passes the full exposure triangle instead, fit runs, and ultimate_ and ibnr_ come back with one column per development age: (1, 1, 10, 10) on raa instead of (1, 1, 10, 1). No error or warning is raised. Summing ibnr_ then counts each origin once per column, so the raa total is 83,931.06 instead of 32,229.96.
When exposure changes with age the first column is also different, because it uses the exposure at the first age instead of the latest one. In a four-origin monthly example the BF ultimates in column 0 were 46.9, 54.72, 64.2, 77.36 with the full triangle against 46.9, 65.76, 78.86, 85.96 with its latest diagonal. CapeCod on that triangle raises ValueError: operands could not be broadcast together with shapes (1,1,22,4) (4,4), which does not point to the cause. On raa, where the exposure is the same at every age, CapeCod still changes column 0: the 1990 ultimate is 18,785.62 with the full triangle and 21,605.83 with the latest diagonal. predict(X, sample_weight=<full triangle>) behaves like fit.
MethodBase.validate_weight (base.py L214–229) compares only shape[:-1], so it never looks at the development axis. #1416 rewrites this function to raise when the first three axes do not broadcast; it still compares shape[:-1], so this case would pass it as well.
How can the bug be reproduced?
import numpy as np
import chainladder as cl
raa = cl.load_sample("raa")
premium = raa.latest_diagonal * 0 + 20000.0
premium_tri = raa * 0 + 20000.0
for w in (premium, premium_tri):
m = cl.BornhuetterFerguson(apriori=0.6).fit(raa, sample_weight=w)
print(w.shape, m.ultimate_.shape, round(float(np.nansum(m.ibnr_.values)), 2))On main ee2c24d (pandas 2.3.3, numpy 2.3.3):
(1, 1, 10, 1) (1, 1, 10, 1) 32229.96
(1, 1, 10, 10) (1, 1, 10, 10) 83931.06
What is the expected behavior?
import pytest
with pytest.raises(ValueError):
cl.BornhuetterFerguson(apriori=0.6).fit(raa, sample_weight=premium_tri)Suggested fix: in validate_weight, raise ValueError("sample_weight must have a single development column; pass e.g. premium.latest_diagonal") when sample_weight.shape[-1] != 1. This would sit alongside the change in #1416. DisposalRate and VotingChainladder call the same function with ultimates. With the check added, the methods, adjustments and workflow test suites pass unchanged (363 passed, as on main).
Would you be willing to contribute this ticket?
- Yes, absolutely!
- Yes, but I would like some help.
- No.
(This issue was written with Árbol, an AI assistant, under my direction.)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Scope
Effort
Projects
- StatusShow more project fieldsReady
Activity
henrydingliu commentedon Nov 19, 2026
lol, i'm actually working on tweaking disposalrate to take a full triangle as sample weight for the paid to paid method for friedland chapter 16 (p 381).
i'm good with the fix. i can retweak disposalrate afterwards.
scks1 commentedon Nov 19, 2026
Thanks. A plain
shape[-1] != 1check invalidate_weightwould block the full-triangle weight you're adding toDisposalRate.DisposalRate.fitandDisposalRate.transformcallMethodBase().validate_weightdirectly at disposal.py L239 and L308. A keyword such asvalidate_weight(X, sample_weight, single_column=True)would letDisposalRatepasssingle_column=Falsewhile the methods keep the check.VotingChainladdergoes through the same check.MethodBase.fitcallsvalidate_weightat base.py L80, andVotingChainladder.predictcalls it at voting.py L358. With the full premium triangle, itsfitstops today with an error that blamesTriangleSelector. With the check in place, the BF estimator inside it would raise first and name the weight.Code
Would you rather fold the check into #1416, or leave it open for a new contributor? It comes to a few lines and one test.
(This comment was written with Árbol, an AI assistant, under my direction.)
henrydingliu commentedon Nov 19, 2026
let's address this now. a 10x10 ultimate is a glaring bug.
scks1 commentedon Nov 19, 2026
Sounds good. I can open the PR now if you want me to take it. It would add a
single_columnkeyword tovalidate_weight, have DisposalRate passFalse, and add one test that covers BF and VotingChainladder. Or would you rather leave it for a new contributor, given the Great First Contribution label?(This comment was written with Árbol, an AI assistant, under my direction.)