casact / chainladder-python

Actuarial reserving in Python
https://chainladder-python.readthedocs.io/en/latest/
Mozilla Public License 2.0
192 stars 71 forks source link

[BUG] Argument validation needed for TailCurve #413

Closed genedan closed 1 year ago

genedan commented 1 year ago

Describe the bug Some invalid arguments for the TailCurve class will raise an exception (although not the kind of exception we'd expect). Others will actually cause no exception when an exception should be raised. I can volunteer to take this one on.

To Reproduce

import chainladder as cl

triangle = cl.load_sample('quarterly')['paid']

cl.TailCurve(
    curve='plExponential'
).fit_transform(triangle)

cl.TailCurve(
    errors='bignore'
)

This leads to:

Traceback (most recent call last):
  File "/usr/lib/python3.10/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 3, in <module>
  File "/home/ubuntu/FASLR/venv/lib/python3.10/site-packages/sklearn/base.py", line 867, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "/home/ubuntu/FASLR/venv/lib/python3.10/site-packages/chainladder/tails/curve.py", line 165, in fit
    tail = self._predict_tail(extrapolate)
  File "/home/ubuntu/FASLR/venv/lib/python3.10/site-packages/chainladder/tails/curve.py", line 192, in _predict_tail
    return self._get_tail_prediction(tail_ldf)
UnboundLocalError: local variable 'tail_ldf' referenced before assignment

For the first case and no exception for the 2nd.

Expected behavior I would expect an invalid argument assignment to raise a valueerror.

Desktop (please complete the following information):