From 32cf8e63b40856993c648bb8f08fa35caab11a96 Mon Sep 17 00:00:00 2001 From: "henrydingliu@gmail.com" Date: Sat, 30 May 2026 03:54:11 +0000 Subject: [PATCH 1/2] fixing triangle.full_expectation_ --- chainladder/core/common.py | 6 ++++- chainladder/core/tests/test_triangle.py | 36 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/chainladder/core/common.py b/chainladder/core/common.py index 7ad6e1f5..c13e9c49 100644 --- a/chainladder/core/common.py +++ b/chainladder/core/common.py @@ -126,7 +126,11 @@ def full_expectation_(self): + "' object has no attribute 'full_expectation_'" ) - return _get_full_expectation(self.cdf_, self.ultimate_, self.X_.is_cumulative) + if hasattr(self, "X_"): + X = self.X_ + else: + X = self + return _get_full_expectation(self.cdf_, self.ultimate_, X.is_cumulative) @property def full_triangle_(self): diff --git a/chainladder/core/tests/test_triangle.py b/chainladder/core/tests/test_triangle.py index 5e34a32a..07c48058 100644 --- a/chainladder/core/tests/test_triangle.py +++ b/chainladder/core/tests/test_triangle.py @@ -637,7 +637,7 @@ def test_origin_as_datetime_arg(clrd): ) -def test_full_triangle_and_full_expectation(raa): +def test_full_triangle_and_full_expectation(raa,atol): raa_cum = raa assert raa_cum.is_cumulative == True @@ -647,24 +647,38 @@ def test_full_triangle_and_full_expectation(raa): assert raa_incr.incr_to_cum() == raa_cum cl_fit_incr = cl.Chainladder().fit(X=raa_incr) + cl_predict_incr = cl.Chainladder().fit_predict(X=raa_incr) assert cl_fit_incr.X_.is_cumulative == False cl_fit_cum = cl.Chainladder().fit(X=raa_cum) + cl_predict_cum = cl.Chainladder().fit_predict(X=raa_cum) assert cl_fit_cum.X_.is_cumulative == True assert cl_fit_incr.cdf_ == cl_fit_cum.cdf_ assert cl_fit_incr.ultimate_ == cl_fit_cum.ultimate_ + assert (np.allclose( + cl_fit_cum.full_expectation_.values, + cl_predict_cum.full_expectation_.values, + atol + ) + ) + assert (np.allclose( + cl_fit_incr.full_expectation_.fillzero.values, + cl_predict_incr.full_expectation_.fillzero.values, + atol + ) + ) assert ( cl_fit_cum.full_expectation_ - cl_fit_incr.full_expectation_.incr_to_cum() - < 0.00001 + < atol ) assert ( - cl_fit_cum.full_triangle_ - cl_fit_incr.full_triangle_.incr_to_cum() < 0.00001 + cl_fit_cum.full_triangle_ - cl_fit_incr.full_triangle_.incr_to_cum() < atol ) assert (cl_fit_cum.full_triangle_ - raa_cum) - ( cl_fit_incr.full_triangle_.incr_to_cum() - raa_incr.incr_to_cum() - ) < 0.00001 + ) < atol bf_fit_incr = cl.BornhuetterFerguson(apriori=1).fit( X=raa_incr, sample_weight=raa_incr.incr_to_cum().latest_diagonal * 0 @@ -681,19 +695,19 @@ def test_full_triangle_and_full_expectation(raa): assert ( bf_fit_cum.full_expectation_ - bf_fit_incr.full_expectation_.incr_to_cum() - < 0.00001 + < atol ) assert ( - bf_fit_cum.full_triangle_ - bf_fit_incr.full_triangle_.incr_to_cum() < 0.00001 + bf_fit_cum.full_triangle_ - bf_fit_incr.full_triangle_.incr_to_cum() < atol ) assert (bf_fit_cum.full_triangle_ - raa_cum) - ( bf_fit_incr.full_triangle_.incr_to_cum() - raa_incr.incr_to_cum() - ) < 0.00001 + ) < atol assert ( cl.Chainladder().fit(raa_incr).full_triangle_ - cl.Chainladder().fit(raa_cum).full_triangle_.cum_to_incr() - <= 0.0001 + <= atol ) bk_fit_incr = cl.Benktander(apriori=1.00, n_iters=2).fit( X=raa_incr, sample_weight=raa_incr.incr_to_cum().latest_diagonal * 0 @@ -704,14 +718,14 @@ def test_full_triangle_and_full_expectation(raa): assert ( bk_fit_cum.full_expectation_ - bk_fit_incr.full_expectation_.incr_to_cum() - < 0.00001 + < atol ) assert ( - bk_fit_cum.full_triangle_ - bk_fit_incr.full_triangle_.incr_to_cum() < 0.00001 + bk_fit_cum.full_triangle_ - bk_fit_incr.full_triangle_.incr_to_cum() < atol ) assert (bk_fit_cum.full_triangle_ - raa_cum) - ( bk_fit_incr.full_triangle_.incr_to_cum() - raa_incr.incr_to_cum() - ) < 0.00001 + ) < atol def test_halfyear_grain(): From 71a8348797b996e8dc4b3c652a32e0c4b89c8f7e Mon Sep 17 00:00:00 2001 From: "henrydingliu@gmail.com" Date: Sat, 30 May 2026 04:09:18 +0000 Subject: [PATCH 2/2] fixing test --- chainladder/core/tests/test_triangle.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chainladder/core/tests/test_triangle.py b/chainladder/core/tests/test_triangle.py index 07c48058..d5b0aab9 100644 --- a/chainladder/core/tests/test_triangle.py +++ b/chainladder/core/tests/test_triangle.py @@ -660,13 +660,13 @@ def test_full_triangle_and_full_expectation(raa,atol): assert (np.allclose( cl_fit_cum.full_expectation_.values, cl_predict_cum.full_expectation_.values, - atol + atol=atol ) ) assert (np.allclose( - cl_fit_incr.full_expectation_.fillzero.values, - cl_predict_incr.full_expectation_.fillzero.values, - atol + cl_fit_incr.full_expectation_.fillzero().values, + cl_predict_incr.full_expectation_.fillzero().values, + atol=atol ) ) assert (