Skip to content

[BUG] TailBondy fails on a pattern fit with Development(groupby=...) #1599

Closed

Description

@scks1

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version (main at 9a4634b: chainladder 0.10.1, Python 3.12.15, numpy 2.3.3, pandas 2.3.3).

Describe the bug in words

With Development(groupby="LOB"), clrd keeps its 779 companies while ldf_ has one row per line (6). TailCurve and TailConstant fit this, but TailBondy builds its starting values with one row per company and its data with one row per line (bondy.py L165–L167), so the concatenate fails. Fixing the starting values alone moves the error to L194–L195, which label b_ with the triangle's index.

TailBondy fits only the pattern, so it can size and label from ldf_ as TailCurve does (curve.py L201, L290). A local two-line change does this: the grouped fit then matches the summed route below in tail_, ldf_ and b_, Chainladder runs on it, and the tails tests pass. The cause differs from #1563, where Mack multiplies the pattern's sigma_ and std_err_ arrays against the triangle. It doesn't depend on #1304 either: the change merges cleanly with it, and #1304's head fails the same way.

TailClark fails on the same pattern (clark.py L165) because it fits its own ClarkLDF on all 779 companies (L152). That looks like the reverse of #1432, where X has fewer rows or columns than ldf_, and #1433's head still fails here.

How can the bug be reproduced?

import chainladder as cl

clrd = cl.load_sample("clrd")["CumPaidLoss"]
dev = cl.Development(groupby="LOB").fit_transform(clrd)
print(clrd.shape, dev.ldf_.shape)
print("TailCurve", cl.TailCurve().fit(dev).ldf_.shape)
for tail in [cl.TailBondy(), cl.TailClark()]:
    try:
        tail.fit(dev)
    except ValueError as e:
        print(type(tail).__name__, e)

# Summing by line first gives the same pattern, and TailBondy fits it.
lob = cl.Development().fit_transform(clrd.groupby("LOB").sum())
print(cl.TailBondy().fit(lob).tail_.round(4))
(779, 1, 10, 10) (6, 1, 1, 9)
TailCurve (6, 1, 1, 11)
TailBondy all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 779 and the array at index 1 has size 6
TailClark all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 6 and the array at index 1 has size 779
LOB
comauto     1.0067
medmal      1.0181
othliab     1.0106
ppauto      1.0009
prodliab    1.0085
wkcomp      1.0102
dtype: float64

TailClark also prints RuntimeWarnings from its ClarkLDF fit, left out above.

What is the expected behavior?

cl.TailBondy().fit(dev) fits one tail per line, the same as the last print.

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Scope

    None yet

    Effort

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions