Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions chainladder/core/tests/test_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3304,3 +3304,22 @@ def test_fit_and_predict_on_single_origin(raa: Triangle, atol) -> None:
np.testing.assert_allclose(
predicted.ultimate_.values.flatten(), [expected], atol=atol
)


def test_fill(clrd: Triangle) -> None:
"""
``Fill`` method works as intended
"""
fill_tri = clrd.iloc[2:4, 4:6].fill(100)
assert np.nansum(fill_tri.values) == 100 * 11 * 10 / 2 * 2 * 2
assert np.nanmax(fill_tri.values) == 100
assert np.nanmin(fill_tri.values) == 100


def test_full_fill(raa: Triangle) -> None:
"""
``Fill`` method works as intended on full triangle
"""
full_tri = cl.Chainladder().fit(raa).full_triangle_
fill_full_tri = full_tri.fill(200)
assert np.all(fill_full_tri.values == np.broadcast_to([200], (1, 1, 10, 12)))
25 changes: 25 additions & 0 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2357,3 +2357,28 @@ def reindex(self, columns=None, fill_value=np.nan):
if column not in obj.columns:
obj[column] = fill_value
return obj

def fill(self, value: float = 1.0, inplace: bool = False) -> Triangle:
"""
Fill the Triangle with a scalar value

Parameters
----------
value : float, default 1.0
All valid elements will be assigned this value
inplace : bool, default False
Whether to mutate the existing Triangle instance or return a new
one.

Returns
-------
Triangle
"""
if inplace:
xp = self.get_array_module()
new_value = self.nan_triangle[None, None, ...].astype(np.float64)
self.values = xp.broadcast_to(new_value * value, self.shape).copy()
return self
else:
obj = self.copy()
return obj.fill(value, True)
4 changes: 2 additions & 2 deletions chainladder/utils/data/friedland_autoprop.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Accident Year,Calendar Year,Reported ALAE,Paid ALAE,Reported Claims,Paid Claims
2000,2007,862,860,116825,116807
2000,2008,862,861,116472,116807
2001,2001,629,480,129430,91475
2001,2002,894,802,139925,113761
2001,2002,894,802,139925,133761
2001,2003,943,882,138161,136143
2001,2004,982,836,137395,136552
2001,2004,982,936,137395,136552
2001,2005,997,975,137269,136818
2001,2006,1002,987,137033,136838
2001,2007,1003,995,136998,136960
Expand Down
Loading