From 376afceee52457b5ed5e97f8dc1df40d296aba6d Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 05:59:55 -0500 Subject: [PATCH 1/6] Use Triangle.equals in the tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace whole-triangle comparisons in the test suite, tri == other and tri != other, with tri.equals(other) and not tri.equals(other). Since the == deprecation each of these comparisons emits a FutureWarning. The tests in test_arithmetic.py that check the deprecation itself keep using ==. Part of #1395. Developed with an AI assistant (Árbol, running Muse). --- .../adjustments/tests/test_berqsherm.py | 2 +- .../adjustments/tests/test_disposal.py | 2 +- chainladder/adjustments/tests/test_trend.py | 2 +- chainladder/core/tests/test_arithmetic.py | 47 +++-- chainladder/core/tests/test_grain.py | 39 ++-- chainladder/core/tests/test_slicing.py | 91 ++++----- chainladder/core/tests/test_triangle.py | 174 ++++++++++-------- .../development/tests/test_development.py | 128 +++++++------ chainladder/methods/tests/test_mack.py | 13 +- chainladder/methods/tests/test_predict.py | 6 +- chainladder/utils/tests/test_tri_w.py | 4 +- chainladder/utils/tests/test_utilities.py | 65 +++---- chainladder/workflow/tests/test_voting.py | 4 +- 13 files changed, 316 insertions(+), 261 deletions(-) diff --git a/chainladder/adjustments/tests/test_berqsherm.py b/chainladder/adjustments/tests/test_berqsherm.py index db5098209..9608d5956 100644 --- a/chainladder/adjustments/tests/test_berqsherm.py +++ b/chainladder/adjustments/tests/test_berqsherm.py @@ -16,7 +16,7 @@ def test_preserve_diagonal(): xp.nansum((berq_triangle.latest_diagonal - triangle.latest_diagonal).values) == 0 ) - assert berq_triangle != triangle + assert not berq_triangle.equals(triangle) def test_adjusted_values(): diff --git a/chainladder/adjustments/tests/test_disposal.py b/chainladder/adjustments/tests/test_disposal.py index 5934c92e7..1bc50e159 100644 --- a/chainladder/adjustments/tests/test_disposal.py +++ b/chainladder/adjustments/tests/test_disposal.py @@ -141,4 +141,4 @@ def test_setting_incr(raa: Triangle) -> None: dr = cl.DisposalRate(n_periods=4).fit(raa, sample_weight=ult) orig_disposal_rate_ = dr.disposal_rate_ dr.incr_disposal_rate_ = dr.incr_disposal_rate_ * 2 - assert dr.disposal_rate_ == orig_disposal_rate_ * 2 + assert dr.disposal_rate_.equals(orig_disposal_rate_ * 2) diff --git a/chainladder/adjustments/tests/test_trend.py b/chainladder/adjustments/tests/test_trend.py index 1b6cbc9c0..855a6a57f 100644 --- a/chainladder/adjustments/tests/test_trend.py +++ b/chainladder/adjustments/tests/test_trend.py @@ -19,7 +19,7 @@ def test_trend1(clrd): ) .ibnr_ ) - assert np.round(lhs, 0) == np.round(rhs, 0) + assert np.round(lhs, 0).equals(np.round(rhs, 0)) def test_trend2(raa): diff --git a/chainladder/core/tests/test_arithmetic.py b/chainladder/core/tests/test_arithmetic.py index c1d8a8cf8..605897b63 100644 --- a/chainladder/core/tests/test_arithmetic.py +++ b/chainladder/core/tests/test_arithmetic.py @@ -32,7 +32,7 @@ def test_arithmetic_ndarray_other_backend(raa: Triangle) -> None: other = np.ones(sparse_raa.shape) result = sparse_raa + other assert result.array_backend == "sparse" - assert result.set_backend("numpy") == raa + 1 + assert result.set_backend("numpy").equals(raa + 1) def test_arithmetic_coo_other_backend(raa: Triangle) -> None: @@ -53,7 +53,7 @@ def test_arithmetic_coo_other_backend(raa: Triangle) -> None: other = COO.from_numpy(np.ones(numpy_raa.shape)) result = numpy_raa + other assert result.array_backend == "sparse" - assert result.set_backend("numpy") == raa + 1 + assert result.set_backend("numpy").equals(raa + 1) def test_arithmetic_grain_mismatch_raises(raa: Triangle, qtr: Triangle) -> None: @@ -95,7 +95,7 @@ def test_non_overlapping_odims(raa: Triangle) -> None: a = raa.iloc[..., :5, :] b = raa.iloc[..., 5:, :] result = a + b - assert result == raa + assert result.equals(raa) def test_arithmetic_union_val_tri(raa: Triangle) -> None: @@ -117,7 +117,7 @@ def test_arithmetic_union_val_tri(raa: Triangle) -> None: result = a + b assert isinstance(result.ddims, pd.DatetimeIndex) assert result.shape == val_raa.shape - assert result == val_raa + assert result.equals(val_raa) def test_origin_broadcasting(raa: Triangle) -> None: @@ -137,22 +137,22 @@ def test_origin_broadcasting(raa: Triangle) -> None: single_origin["values"] = 500 result = raa + single_origin assert result.shape == raa.shape - assert result == raa + 500 + assert result.equals(raa + 500) def test_arithmetic_union(raa): assert raa.shape == (raa - raa[raa.valuation < "1987"]).shape - assert raa[raa.valuation < "1986"] + raa[raa.valuation >= "1986"] == raa + assert (raa[raa.valuation < "1986"] + raa[raa.valuation >= "1986"]).equals(raa) def test_arithmetic_across_keys(qtr): - assert (qtr.sum(1) - qtr.iloc[:, 0]) == qtr.iloc[:, 1] + assert (qtr.sum(1) - qtr.iloc[:, 0]).equals(qtr.iloc[:, 1]) def test_arithmetic_1(raa): x = raa - assert -(((x / x) + 0) * x) == -(+x) - assert 1 - (x / x) == 0 * x * 0 + assert (-(((x / x) + 0) * x)).equals(-(+x)) + assert (1 - (x / x)).equals(0 * x * 0) def test_eq_non_triangle(raa: Triangle) -> None: @@ -258,7 +258,7 @@ def test_vector_division(raa: Triangle) -> None: for i in range(raa.shape[2]): orig = raa.iloc[..., i : i + 1, :] ld = raa.latest_diagonal.iloc[..., i : i + 1, :] - assert result.iloc[..., i : i + 1, :] == ld / orig + assert result.iloc[..., i : i + 1, :].equals(ld / orig) def test_multiindex_broadcast(clrd): @@ -312,7 +312,7 @@ def test_index_broadcasting5(clrd): a = clrd["CumPaidLoss"].iloc[:300] b = clrd["CumPaidLoss"].iloc[300:] c = a + b - assert c.sort_index() == clrd["CumPaidLoss"].sort_index() + assert c.sort_index().equals(clrd["CumPaidLoss"].sort_index()) def test_index_broadacsting6(clrd): @@ -320,7 +320,7 @@ def test_index_broadacsting6(clrd): b = clrd["CumPaidLoss"].iloc[50:150] c = clrd["CumPaidLoss"].iloc[50:100] d = a + b - c - assert d.sort_index() == clrd["CumPaidLoss"].iloc[:150].sort_index() + assert d.sort_index().equals(clrd["CumPaidLoss"].iloc[:150].sort_index()) def test_index_broadcasting_ambiguous(clrd: Triangle) -> None: @@ -361,11 +361,10 @@ def test_prep_columns_reindexes_superset(clrd: Triangle) -> None: y = clrd[["CumPaidLoss", "IncurLoss"]] for result in [x + y, y + x]: assert set(result.columns) == {"CumPaidLoss", "EarnedPremNet", "IncurLoss"} - assert ( - result[["CumPaidLoss", "IncurLoss"]] - == clrd[["CumPaidLoss", "IncurLoss"]] * 2 + assert result[["CumPaidLoss", "IncurLoss"]].equals( + clrd[["CumPaidLoss", "IncurLoss"]] * 2 ) - assert result["EarnedPremNet"] == clrd["EarnedPremNet"] + assert result["EarnedPremNet"].equals(clrd["EarnedPremNet"]) def test_overlapping_columns_and_origins_union_both_axes(clrd: Triangle) -> None: @@ -397,23 +396,21 @@ def test_overlapping_columns_and_origins_union_both_axes(clrd: Triangle) -> None both = both[both.origin <= "1993"] expected = c[c.origin >= "1990"] expected = expected[expected.origin <= "1993"] - assert both["IncurLoss"] == expected["IncurLoss"] * 2 + assert both["IncurLoss"].equals(expected["IncurLoss"] * 2) a_only = result[result.origin <= "1989"] - assert a_only["IncurLoss"] == c[c.origin <= "1989"]["IncurLoss"] + assert a_only["IncurLoss"].equals(c[c.origin <= "1989"]["IncurLoss"]) b_only = result[result.origin >= "1994"] - assert b_only["IncurLoss"] == c[c.origin >= "1994"]["IncurLoss"] + assert b_only["IncurLoss"].equals(c[c.origin >= "1994"]["IncurLoss"]) - assert ( - result["CumPaidLoss"][result.origin <= "1993"] - == c["CumPaidLoss"][c.origin <= "1993"] + assert result["CumPaidLoss"][result.origin <= "1993"].equals( + c["CumPaidLoss"][c.origin <= "1993"] ) assert np.isnan(result["CumPaidLoss"][result.origin >= "1994"].values).all() - assert ( - result["EarnedPremDIR"][result.origin >= "1990"] - == c["EarnedPremDIR"][c.origin >= "1990"] + assert result["EarnedPremDIR"][result.origin >= "1990"].equals( + c["EarnedPremDIR"][c.origin >= "1990"] ) assert np.isnan(result["EarnedPremDIR"][result.origin <= "1989"].values).all() diff --git a/chainladder/core/tests/test_grain.py b/chainladder/core/tests/test_grain.py index df395c9f3..ddda6261b 100644 --- a/chainladder/core/tests/test_grain.py +++ b/chainladder/core/tests/test_grain.py @@ -32,28 +32,41 @@ def test_grain(qtr): def test_grain_returns_valid_tri(qtr): - assert qtr.grain("OYDY").latest_diagonal == qtr.latest_diagonal + assert qtr.grain("OYDY").latest_diagonal.equals(qtr.latest_diagonal) def test_grain_increm_arg(qtr): clrd_i = qtr["incurred"].cum_to_incr() a = clrd_i.grain("OYDY").incr_to_cum() - assert a == qtr["incurred"].grain("OYDY") + assert a.equals(qtr["incurred"].grain("OYDY")) def test_commutative(qtr, atol): full = cl.Chainladder().fit(qtr).full_expectation_ - assert qtr.grain("OYDY").val_to_dev() == qtr.val_to_dev().grain("OYDY") - assert qtr.cum_to_incr().grain( - "OYDY" - ).val_to_dev() == qtr.val_to_dev().cum_to_incr().grain("OYDY") - assert qtr.grain( - "OYDY" - ).cum_to_incr().val_to_dev().incr_to_cum() == qtr.val_to_dev().grain("OYDY") - assert full.grain("OYDY").val_to_dev() == full.val_to_dev().grain("OYDY") - assert full.cum_to_incr().grain( - "OYDY" - ).val_to_dev() == full.val_to_dev().cum_to_incr().grain("OYDY") + assert qtr.grain("OYDY").val_to_dev().equals(qtr.val_to_dev().grain("OYDY")) + assert ( + qtr + .cum_to_incr() + .grain("OYDY") + .val_to_dev() + .equals(qtr.val_to_dev().cum_to_incr().grain("OYDY")) + ) + assert ( + qtr + .grain("OYDY") + .cum_to_incr() + .val_to_dev() + .incr_to_cum() + .equals(qtr.val_to_dev().grain("OYDY")) + ) + assert full.grain("OYDY").val_to_dev().equals(full.val_to_dev().grain("OYDY")) + assert ( + full + .cum_to_incr() + .grain("OYDY") + .val_to_dev() + .equals(full.val_to_dev().cum_to_incr().grain("OYDY")) + ) a = full.grain("OYDY").cum_to_incr().val_to_dev().incr_to_cum() b = full.val_to_dev().grain("OYDY") assert abs(a - b).max().max().max() < atol diff --git a/chainladder/core/tests/test_slicing.py b/chainladder/core/tests/test_slicing.py index 4a8d7cbd6..3a06b0fd4 100644 --- a/chainladder/core/tests/test_slicing.py +++ b/chainladder/core/tests/test_slicing.py @@ -13,8 +13,9 @@ def test_slice_by_boolean(clrd: Triangle) -> None: assert ( - clrd[clrd["LOB"] == "ppauto"].loc["Wolverine Mut Ins Co"]["CumPaidLoss"] - == clrd.loc["Wolverine Mut Ins Co"].loc["ppauto"]["CumPaidLoss"] + clrd[clrd["LOB"] == "ppauto"] + .loc["Wolverine Mut Ins Co"]["CumPaidLoss"] + .equals(clrd.loc["Wolverine Mut Ins Co"].loc["ppauto"]["CumPaidLoss"]) ) @@ -64,57 +65,55 @@ def test_slice_by_loc_iloc(clrd): def test_slicers_honor_order(clrd): clrd = clrd.groupby("LOB").sum() - assert clrd.iloc[[1, 0], :].iloc[0, 1] == clrd.iloc[1, 1] # row - assert clrd.iloc[[1, 0], [1, 0]].iloc[0, 0] == clrd.iloc[1, 1] # col - assert clrd.loc[:, ["CumPaidLoss", "IncurLoss"]].iloc[0, 0] == clrd.iloc[0, 1] + assert clrd.iloc[[1, 0], :].iloc[0, 1].equals(clrd.iloc[1, 1]) # row + assert clrd.iloc[[1, 0], [1, 0]].iloc[0, 0].equals(clrd.iloc[1, 1]) # col + assert clrd.loc[:, ["CumPaidLoss", "IncurLoss"]].iloc[0, 0].equals(clrd.iloc[0, 1]) assert ( - clrd.loc[["ppauto", "medmal"], ["CumPaidLoss", "IncurLoss"]].iloc[0, 0] - == clrd.iloc[3]["CumPaidLoss"] + clrd + .loc[["ppauto", "medmal"], ["CumPaidLoss", "IncurLoss"]] + .iloc[0, 0] + .equals(clrd.iloc[3]["CumPaidLoss"]) ) - assert ( - clrd.loc[clrd["LOB"] == "comauto", ["CumPaidLoss", "IncurLoss"]] - == clrd[clrd["LOB"] == "comauto"].iloc[:, [1, 0]] + assert clrd.loc[clrd["LOB"] == "comauto", ["CumPaidLoss", "IncurLoss"]].equals( + clrd[clrd["LOB"] == "comauto"].iloc[:, [1, 0]] ) - assert clrd.groupby("LOB").sum() == clrd + assert clrd.groupby("LOB").sum().equals(clrd) def test_backends(clrd): clrd = clrd[["CumPaidLoss", "EarnedPremDIR"]] a = clrd.iloc[1, 0].set_backend("sparse").dropna() b = clrd.iloc[1, 0].dropna() - assert a == b + assert a.equals(b) def test_union_columns(clrd): - assert clrd.iloc[:, :3] + clrd.iloc[:, 3:] == clrd + assert (clrd.iloc[:, :3] + clrd.iloc[:, 3:]).equals(clrd) def test_4loc(clrd): clrd = clrd.groupby("LOB").sum() - assert ( - clrd.iloc[:3, :2, 0, 0] - == clrd[clrd.origin == clrd.origin.min()][ + assert clrd.iloc[:3, :2, 0, 0].equals( + clrd[clrd.origin == clrd.origin.min()][ clrd.development == clrd.development.min() ].loc["comauto":"othliab", :"CumPaidLoss", :, :] ) - assert ( - clrd.iloc[:3, :2, 0:1, -1] - == clrd[clrd.development == clrd.development.max()].loc[ + assert clrd.iloc[:3, :2, 0:1, -1].equals( + clrd[clrd.development == clrd.development.max()].loc[ "comauto":"othliab", :"CumPaidLoss", "1988", : ] ) def test_loc_ellipsis(clrd): - assert ( - clrd.loc["Aegis Grp"] - == clrd.loc["Adriatic Ins Co":"Aegis Grp"].loc["Aegis Grp"] + assert clrd.loc["Aegis Grp"].equals( + clrd.loc["Adriatic Ins Co":"Aegis Grp"].loc["Aegis Grp"] ) - assert clrd.loc["Aegis Grp", ..., :] == clrd.loc["Aegis Grp"] - assert clrd.loc[..., 24:] == clrd.loc[..., :, 24:] - assert clrd.loc[:, ..., 24:] == clrd.loc[..., :, 24:] - assert clrd.loc[:, "CumPaidLoss"] == clrd.loc[:, "CumPaidLoss", ...] - assert clrd.loc[..., "CumPaidLoss", :, :] == clrd.loc[:, "CumPaidLoss", :, :] + assert clrd.loc["Aegis Grp", ..., :].equals(clrd.loc["Aegis Grp"]) + assert clrd.loc[..., 24:].equals(clrd.loc[..., :, 24:]) + assert clrd.loc[:, ..., 24:].equals(clrd.loc[..., :, 24:]) + assert clrd.loc[:, "CumPaidLoss"].equals(clrd.loc[:, "CumPaidLoss", ...]) + assert clrd.loc[..., "CumPaidLoss", :, :].equals(clrd.loc[:, "CumPaidLoss", :, :]) def test_missing_first_lag(raa): @@ -139,12 +138,12 @@ def set_missing(values) -> None: def test_reverse_slice_integrity(clrd): assert clrd.iloc[::-1, ::-1].shape == clrd.shape assert np.all(clrd.iloc[:, ::-1].columns.values == clrd.columns[::-1]) - assert clrd.iloc[clrd.index.index[::-1]] + clrd == 2 * clrd + assert (clrd.iloc[clrd.index.index[::-1]] + clrd).equals(2 * clrd) def test_loc_tuple(clrd): assert len(clrd.loc[("Adriatic Ins Co", "othliab")]) == 1 - assert clrd.loc[clrd.index] == clrd + assert clrd.loc[clrd.index].equals(clrd) def test_at_iat(raa): @@ -156,7 +155,7 @@ def test_at_iat(raa): raa2.iat[0, 0, 4, -1] = 5 assert raa2.iat[0, 0, 4, -1] == 5 raa2.iat[-1, -1, 4, 0] = 5 - assert raa1 == raa2 + assert raa1.equals(raa2) def test_at_iat_exceptions(raa): @@ -291,7 +290,7 @@ def test_loc_setitem_triangle_value(clrd: Triangle) -> None: tri.loc["Aegis Grp", "comauto"] = sub * 2 else: tri.loc["Aegis Grp", "comauto"] = sub * 2 - assert tri.loc["Aegis Grp", "comauto"] == sub * 2 + assert tri.loc["Aegis Grp", "comauto"].equals(sub * 2) def test_loc_setitem_partial_triangles(raa: Triangle) -> None: @@ -314,11 +313,11 @@ def test_loc_setitem_partial_triangles(raa: Triangle) -> None: # Test is specific to the numpy backend. raa_new.loc[:, :, :, :60] = raa2.loc[:, :, :, :60] raa_new.loc[:, :, :, 72:] = raa2.loc[:, :, :, 72:] - assert raa_new == raa2 + assert raa_new.equals(raa2) raa_new = raa.copy() raa_new.loc[:, :, :"1984", :] = raa2.loc[:, :, :"1984", :] raa_new.loc[:, :, "1985":, :] = raa2.loc[:, :, "1985":, :] - assert raa_new == raa2 + assert raa_new.equals(raa2) def test_invalid_iloc_sparse_assignment(prism) -> None: @@ -515,13 +514,13 @@ def test_loc_setting_non_contiguous_index_and_columns(clrd: Triangle) -> None: val_col = ["IncurLoss", "CumPaidLoss", "EarnedPremNet"] clrd_copy = clrd.copy() clrd_copy.loc[dest_index] = clrd.loc[val_index] - assert clrd_copy.loc[dest_index] == clrd.loc[val_index] + assert clrd_copy.loc[dest_index].equals(clrd.loc[val_index]) clrd_copy = clrd.copy() clrd_copy.loc[:, dest_col] = clrd.loc[:, val_col] - assert clrd_copy.loc[:, dest_col] == clrd.loc[:, val_col] + assert clrd_copy.loc[:, dest_col].equals(clrd.loc[:, val_col]) clrd_copy = clrd.copy() clrd_copy.loc[dest_index, dest_col] = clrd.loc[val_index, val_col] - assert clrd_copy.loc[dest_index, dest_col] == clrd.loc[val_index, val_col] + assert clrd_copy.loc[dest_index, dest_col].equals(clrd.loc[val_index, val_col]) def test_iloc_setting_non_contiguous_index_and_columns(clrd: Triangle) -> None: @@ -547,20 +546,22 @@ def test_iloc_setting_non_contiguous_index_and_columns(clrd: Triangle) -> None: val_col = [1, 2, 4] clrd_copy = clrd.copy() clrd_copy.iloc[dest_index] = clrd.iloc[val_index] - assert clrd_copy.iloc[dest_index] == clrd.iloc[val_index] + assert clrd_copy.iloc[dest_index].equals(clrd.iloc[val_index]) clrd_copy = clrd.copy() clrd_copy.iloc[:, dest_col] = clrd.iloc[:, val_col] - assert clrd_copy.iloc[:, dest_col] == clrd.iloc[:, val_col] + assert clrd_copy.iloc[:, dest_col].equals(clrd.iloc[:, val_col]) clrd_copy = clrd.copy() clrd_copy.iloc[dest_index, dest_col] = clrd.iloc[val_index, val_col] - assert clrd_copy.iloc[dest_index, dest_col] == clrd.iloc[val_index, val_col] + assert clrd_copy.iloc[dest_index, dest_col].equals( + clrd.iloc[val_index, val_col] + ) def test_sparse_at_iat1(prism): t = prism.copy() t.iat[0, 0, 0, 0] = 5.0 t.at[12138, "reportedCount", "2008-01", 1] = 0 - assert t == prism + assert t.equals(prism) def test_sparse_iat_setitem_triangleslicer_value(prism: Triangle) -> None: @@ -622,7 +623,7 @@ def test_setitem_virtual_column_numpy_backend(raa: Triangle) -> None: # Test is specific to the numpy backend. tri["double"] = lambda x: x["values"] * 2 assert "double" in tri.columns - assert tri["double"] == tri["values"] * 2 + assert tri["double"].equals(tri["values"] * 2) def test_setitem_value_backend_conversion(raa: Triangle) -> None: @@ -644,7 +645,7 @@ def test_setitem_value_backend_conversion(raa: Triangle) -> None: assert tri.array_backend != value.array_backend tri["values"] = value assert tri.array_backend == raa.array_backend - assert tri["values"] == raa["values"] * 2 + assert tri["values"].equals(raa["values"] * 2) def test_setitem_existing_column_triangle_value(raa: Triangle) -> None: @@ -663,7 +664,7 @@ def test_setitem_existing_column_triangle_value(raa: Triangle) -> None: tri = raa.copy() value = tri["values"] * 2 tri["values"] = value - assert tri["values"] == raa["values"] * 2 + assert tri["values"].equals(raa["values"] * 2) def test_setitem_existing_column_array_value(raa: Triangle) -> None: @@ -683,7 +684,7 @@ def test_setitem_existing_column_array_value(raa: Triangle) -> None: value = (tri["values"] * 3).values assert not isinstance(value, type(tri)) tri["values"] = value - assert tri["values"] == raa["values"] * 3 + assert tri["values"].equals(raa["values"] * 3) def test_sparse_column_assignment(prism): @@ -693,7 +694,7 @@ def test_sparse_column_assignment(prism): t["Paid2"] = lambda x: x["Paid"] # Existing from virtual t["Paid"] = t["Paid2"] # Existing from physical t["Paid3"] = lambda x: x["Paid"] # New from virtual - assert out == t["Paid"] + assert out.equals(t["Paid"]) assert t.shape == (34244, 6, 120, 120) diff --git a/chainladder/core/tests/test_triangle.py b/chainladder/core/tests/test_triangle.py index 233ccd2ec..9f76e4bed 100644 --- a/chainladder/core/tests/test_triangle.py +++ b/chainladder/core/tests/test_triangle.py @@ -141,7 +141,7 @@ def test_align_pattern(raa, atol): def test_incr_to_cum(clrd): - clrd.cum_to_incr().incr_to_cum() == clrd + clrd.cum_to_incr().incr_to_cum().equals(clrd) def test_create_new_value(clrd): @@ -156,29 +156,31 @@ def test_create_new_value(clrd): def test_multilevel_index_groupby_sum1(clrd): - assert clrd.groupby("LOB").sum().sum() == clrd.sum() + assert clrd.groupby("LOB").sum().sum().equals(clrd.sum()) def test_multilevel_index_groupby_sum2(clrd): a = clrd.groupby("GRNAME").sum().sum() b = clrd.groupby("LOB").sum().sum() - assert a == b + assert a.equals(b) def test_boolean_groupby_eq_groupby_loc(clrd): assert ( - clrd[clrd["LOB"] == "ppauto"].sum() == clrd.groupby("LOB").sum().loc["ppauto"] + clrd[clrd["LOB"] == "ppauto"] + .sum() + .equals(clrd.groupby("LOB").sum().loc["ppauto"]) ) def test_latest_diagonal_two_routes(clrd): - assert ( - clrd.latest_diagonal.sum()["BulkLoss"] == clrd.sum().latest_diagonal["BulkLoss"] + assert clrd.latest_diagonal.sum()["BulkLoss"].equals( + clrd.sum().latest_diagonal["BulkLoss"] ) def test_sum_of_diff_eq_diff_of_sum(clrd): - assert (clrd["BulkLoss"] - clrd["CumPaidLoss"]).latest_diagonal == ( + assert (clrd["BulkLoss"] - clrd["CumPaidLoss"]).latest_diagonal.equals( clrd.latest_diagonal["BulkLoss"] - clrd.latest_diagonal["CumPaidLoss"] ) @@ -186,7 +188,7 @@ def test_sum_of_diff_eq_diff_of_sum(clrd): def test_append(raa): raa2 = raa.copy() raa2.index = pd.DataFrame([["P2"]], columns=raa.key_labels) - assert raa.append(raa2).sum() == 2 * raa + assert raa.append(raa2).sum().equals(2 * raa) def test_rename_columns(genins, clrd) -> None: @@ -256,7 +258,7 @@ def test_printer(raa): def test_value_order(clrd): a = clrd[["CumPaidLoss", "BulkLoss"]] b = clrd[["BulkLoss", "CumPaidLoss"]] - assert a.iloc[:, -1] == b.iloc[:, 0] + assert a.iloc[:, -1].equals(b.iloc[:, 0]) def test_trend(raa, atol): @@ -287,11 +289,11 @@ def test_trend_invalid_axis_raises(raa: Triangle) -> None: def test_valuation_shift(qtr): x = qtr.iloc[0, 0] - assert x[x.valuation <= x.valuation_date] == x + assert x[x.valuation <= x.valuation_date].equals(x) def test_quantile_vs_median(clrd): - assert clrd.quantile(q=0.5)["CumPaidLoss"] == clrd.median()["CumPaidLoss"] + assert clrd.quantile(q=0.5)["CumPaidLoss"].equals(clrd.median()["CumPaidLoss"]) def test_base_minimum_exposure_triangle(raa): @@ -366,7 +368,7 @@ def test_index_setter_with_dataframe(clrd: Triangle) -> None: assert tri.index.equals(new_index) # _set_slicers() must have rebuilt .loc against the new key label. assert tri.loc["A"].index.values.tolist() == [["A"]] - assert tri.loc["A"] == clrd.iloc[:1] + assert tri.loc["A"].equals(clrd.iloc[:1]) def test_index_setter_length_mismatch_raises(clrd: Triangle) -> None: @@ -692,7 +694,7 @@ def test_legacy_kdims_vdims_migration(self, raa): assert restored.index.equals(raa.index) assert list(restored.columns) == list(raa.columns) assert restored.loc["Total"].shape == raa.loc["Total"].shape - assert restored == raa + assert restored.equals(raa) assert 0 in restored._axes assert restored._axes[0].equals(raa.index) assert 1 in restored._axes @@ -730,7 +732,7 @@ def test_migrated_pickle_roundtrip(self, raa): with warnings.catch_warnings(): warnings.simplefilter("error", UserWarning) roundtripped = pickle.loads(pickle.dumps(restored)) - assert roundtripped == raa + assert roundtripped.equals(raa) assert 0 in roundtripped._axes assert 1 in roundtripped._axes @@ -746,7 +748,7 @@ def test_sort_axis_columns_out_of_order(raa): def test_valdev1(qtr): - assert qtr.dev_to_val().val_to_dev() == qtr + assert qtr.dev_to_val().val_to_dev().equals(qtr) def test_dev_to_val_inplace_on_val_tri_returns_self(qtr: Triangle) -> None: @@ -774,13 +776,13 @@ def test_dev_to_val_inplace_on_val_tri_returns_self(qtr: Triangle) -> None: def test_valdev2(qtr): a = qtr.dev_to_val().grain("OYDY").val_to_dev() b = qtr.grain("OYDY") - assert a == b + assert a.equals(b) def test_valdev3(qtr): a = qtr.grain("OYDY").dev_to_val().val_to_dev() b = qtr.grain("OYDY") - assert a == b + assert a.equals(b) def test_valdev4(raa: Triangle) -> None: @@ -859,8 +861,8 @@ def test_drop_column_string_axis(clrd): """drop() should accept 'columns' as a string alias for axis 1.""" result = clrd.drop(labels="CumPaidLoss", axis="columns") assert "CumPaidLoss" not in result.columns - assert clrd.drop(labels="CumPaidLoss", axis="columns") == clrd.drop( - labels="CumPaidLoss", axis=1 + assert clrd.drop(labels="CumPaidLoss", axis="columns").equals( + clrd.drop(labels="CumPaidLoss", axis=1) ) @@ -888,7 +890,7 @@ def test_drop_columns_alternative(clrd): """columns= should be equivalent to labels=..., axis=1.""" result = clrd.drop(columns="CumPaidLoss") assert "CumPaidLoss" not in result.columns - assert result == clrd.drop(labels="CumPaidLoss", axis=1) + assert result.equals(clrd.drop(labels="CumPaidLoss", axis=1)) def test_drop_columns_alternative_list(clrd): @@ -896,7 +898,7 @@ def test_drop_columns_alternative_list(clrd): result = clrd.drop(columns=["CumPaidLoss", "IncurLoss"]) assert "CumPaidLoss" not in result.columns assert "IncurLoss" not in result.columns - assert result == clrd.drop(labels=["CumPaidLoss", "IncurLoss"], axis=1) + assert result.equals(clrd.drop(labels=["CumPaidLoss", "IncurLoss"], axis=1)) def test_drop_labels_and_alternative_raises(clrd): @@ -922,8 +924,8 @@ def test_drop_columns_alternative_index_like(clrd): labels = clrd.columns[:2] result = clrd.drop(columns=labels) assert all(label not in result.columns for label in labels) - assert result == clrd.drop(columns=list(labels)) - assert result == clrd.drop(columns=labels.values) + assert result.equals(clrd.drop(columns=list(labels))) + assert result.equals(clrd.drop(columns=labels.values)) @pytest.fixture @@ -976,8 +978,8 @@ def test_drop_origin_keeps_populated_development(origin_tri): def test_drop_origin_axis_equivalents(origin_tri): """labels + axis=2/'origin' should equal the origin= alternative.""" expected = origin_tri.drop(origin="1987") - assert expected == origin_tri.drop(labels="1987", axis=2) - assert expected == origin_tri.drop(labels="1987", axis="origin") + assert expected.equals(origin_tri.drop(labels="1987", axis=2)) + assert expected.equals(origin_tri.drop(labels="1987", axis="origin")) def test_drop_origin_interior_raises(origin_tri): @@ -1025,8 +1027,8 @@ def test_drop_development_first(raa): def test_drop_development_axis_equivalents(raa): """labels + axis=3/'development' should equal the development= alternative.""" expected = raa.drop(development=120) - assert expected == raa.drop(labels=120, axis=3) - assert expected == raa.drop(labels=120, axis="development") + assert expected.equals(raa.drop(labels=120, axis=3)) + assert expected.equals(raa.drop(labels=120, axis="development")) def test_drop_development_interior_raises(raa): @@ -1056,11 +1058,11 @@ def test_drop_both_labels_and_alternative_raises(raa): def test_drop_errors_ignore(raa): """errors='ignore' should suppress KeyError for missing labels.""" res_col = raa.drop(columns="nonexistent_col", errors="ignore") - assert res_col == raa + assert res_col.equals(raa) res_orig = raa.drop(origin="1800", errors="ignore") - assert res_orig == raa + assert res_orig.equals(raa) res_dev = raa.drop(development=999, errors="ignore") - assert res_dev == raa + assert res_dev.equals(raa) with pytest.raises(ValueError, match="errors must be"): raa.drop(columns="CumPaidLoss", errors="invalid") @@ -1196,27 +1198,29 @@ def test_exposure_tri(): y = cl.Triangle(x, origin="origin", index="LOB", columns="paid", cumulative=True) x = cl.load_sample("auto")["paid"] x = x[x.development == 12] - assert x == y + assert x.equals(y) def test_jagged_1_add(raa): raa1 = raa[raa.origin <= "1984"] raa2 = raa[raa.origin > "1984"] - assert raa2 + raa1 == raa - assert raa2.dropna() + raa1.dropna() == raa + assert (raa2 + raa1).equals(raa) + assert (raa2.dropna() + raa1.dropna()).equals(raa) def test_jagged_2_add(raa): raa1 = raa[raa.development <= 48] raa2 = raa[raa.development > 48] - assert raa2 + raa1 == raa - assert raa2.dropna() + raa1.dropna() == raa + assert (raa2 + raa1).equals(raa) + assert (raa2.dropna() + raa1.dropna()).equals(raa) def test_df_period_input(raa): d = raa.latest_diagonal df = d.to_frame(origin_as_datetime=False).reset_index() - assert cl.Triangle(df, origin="index", columns=df.columns[-1], cumulative=True) == d + assert cl.Triangle( + df, origin="index", columns=df.columns[-1], cumulative=True + ).equals(d) def test_trend_on_vector(raa): @@ -1228,12 +1232,14 @@ def test_trend_on_vector(raa): def test_latest_diagonal_val_to_dev(raa): - assert raa.latest_diagonal.val_to_dev() == raa[raa.valuation == raa.valuation_date] + assert raa.latest_diagonal.val_to_dev().equals( + raa[raa.valuation == raa.valuation_date] + ) def test_sumdiff_to_diffsum(clrd): out = clrd["CumPaidLoss"] - assert out.cum_to_incr().incr_to_cum().sum() == out.sum() + assert out.cum_to_incr().incr_to_cum().sum().equals(out.sum()) def test_init_vector(raa): @@ -1283,7 +1289,7 @@ def test_groupby_agg_auto_sparse(prism: Triangle) -> None: assert result_default.array_backend == "numpy" assert result_no_sparse.array_backend == "sparse" - assert result_default == result_no_sparse + assert result_default.equals(result_no_sparse) def test_auto_sparse_disabled_returns_self(prism: Triangle) -> None: @@ -1553,7 +1559,7 @@ def test_triangle_from_dataframe_interchange_protocol() -> None: cumulative=True, ) - assert tri == expected + assert tri.equals(expected) def test_array_function_unhandled_raises(raa: Triangle) -> None: @@ -1616,7 +1622,9 @@ def test_get_axis_none(clrd: Triangle) -> None: ------- None """ - assert clrd.groupby("LOB", axis=None).sum() == clrd.groupby("LOB", axis=0).sum() + assert ( + clrd.groupby("LOB", axis=None).sum().equals(clrd.groupby("LOB", axis=0).sum()) + ) def test_astype(raa: Triangle) -> None: @@ -1781,22 +1789,28 @@ def test_partial_year(prism): def test_array_protocol(raa, clrd): - assert np.sqrt(raa) == raa.sqrt() - assert np.concatenate((clrd.iloc[:200], clrd.iloc[200:]), 0) == cl.concat( - (clrd.iloc[:200], clrd.iloc[200:]), 0 + assert np.sqrt(raa).equals(raa.sqrt()) + assert np.concatenate((clrd.iloc[:200], clrd.iloc[200:]), 0).equals( + cl.concat((clrd.iloc[:200], clrd.iloc[200:]), 0) ) def test_partial_val_dev(raa): raa = raa.latest_diagonal raa.iloc[..., -3:, :] = np.nan - raa.val_to_dev().iloc[0, 0, 0, -1] == raa.iloc[0, 0, 0, -1] + raa.val_to_dev().iloc[0, 0, 0, -1].equals(raa.iloc[0, 0, 0, -1]) def test_sort_axis(clrd): - assert clrd.iloc[::-1, ::-1, ::-1, ::-1].sort_axis(0).sort_axis(1).sort_axis( - 2 - ).sort_axis(3) == clrd.sort_axis(1) + assert ( + clrd + .iloc[::-1, ::-1, ::-1, ::-1] + .sort_axis(0) + .sort_axis(1) + .sort_axis(2) + .sort_axis(3) + .equals(clrd.sort_axis(1)) + ) def test_sort_axis_columns_reorders_values() -> None: @@ -2060,7 +2074,7 @@ def test_ffill_invalid_axis_raises(raa: Triangle) -> None: def test_array_protocol2(raa): import numpy as np - assert raa.log().exp() == np.exp(np.log(raa)) + assert raa.log().exp().equals(np.exp(np.log(raa))) def test_create_full_triangle(raa): @@ -2072,7 +2086,7 @@ def test_create_full_triangle(raa): columns="values", cumulative=True, ) - assert a == b + assert a.equals(b) def test_create_triangle_with_ultimates(raa): @@ -2086,7 +2100,7 @@ def test_create_triangle_with_ultimates(raa): cumulative=True, ) assert round_tripped.is_ultimate - assert round_tripped == ult + assert round_tripped.equals(ult) direct = cl.Triangle( pd.DataFrame({ @@ -2104,15 +2118,17 @@ def test_create_triangle_with_ultimates(raa): def test_groupby_getitem(clrd): assert ( - clrd.groupby("LOB")["CumPaidLoss"].sum() - == clrd["CumPaidLoss"].groupby("LOB").sum() + clrd + .groupby("LOB")["CumPaidLoss"] + .sum() + .equals(clrd["CumPaidLoss"].groupby("LOB").sum()) ) def test_virtual_column(prism): prism["P"] = prism["Paid"] prism["Paid"] = lambda x: x["P"] - assert prism["Paid"] == prism["P"] + assert prism["Paid"].equals(prism["P"]) def test_to_frame_keepdims_virtual_column(clrd: Triangle) -> None: @@ -2166,7 +2182,7 @@ def test_pipe(raa): def f(x): return x.loc[..., 48:] - assert raa.loc[..., 48:] == raa.pipe(f) + assert raa.loc[..., 48:].equals(raa.pipe(f)) def test_repr_html(raa, clrd): @@ -2228,7 +2244,7 @@ def test_sparse_reassignment_no_mutate(prism): x["Capped 100k Paid"] = cl.minimum(x["Paid"], 100000) x["Excess 100k Paid"] = x["Paid"] - x["Capped 100k Paid"] b = x["Excess 100k Paid"].sum().grain("OYDY") - assert a == b + assert a.equals(b) def test_trailing_origin(): @@ -2282,7 +2298,7 @@ def test_trailing_valuation(): trailing=True, cumulative=True, ) - assert tri == tri2 + assert tri.equals(tri2) def test_edgecase_236(): @@ -2370,7 +2386,7 @@ def test_full_triangle_and_full_expectation(raa, atol): raa_incr = raa_cum.cum_to_incr() assert not raa_incr.is_cumulative assert raa_incr.incr_to_cum().is_cumulative - assert raa_incr.incr_to_cum() == raa_cum + assert raa_incr.incr_to_cum().equals(raa_cum) cl_fit_incr = cl.Chainladder().fit(X=raa_incr) cl_predict_incr = cl.Chainladder().fit_predict(X=raa_incr) @@ -2380,8 +2396,8 @@ def test_full_triangle_and_full_expectation(raa, atol): cl_predict_cum = cl.Chainladder().fit_predict(X=raa_cum) assert cl_fit_cum.X_.is_cumulative - assert cl_fit_incr.cdf_ == cl_fit_cum.cdf_ - assert cl_fit_incr.ultimate_ == cl_fit_cum.ultimate_ + assert cl_fit_incr.cdf_.equals(cl_fit_cum.cdf_) + assert cl_fit_incr.ultimate_.equals(cl_fit_cum.ultimate_) assert np.allclose( cl_fit_cum.full_expectation_.values, @@ -2412,8 +2428,8 @@ def test_full_triangle_and_full_expectation(raa, atol): ) assert bf_fit_cum.X_.is_cumulative - assert bf_fit_incr.cdf_ == bf_fit_cum.cdf_ - assert bf_fit_incr.ultimate_ == bf_fit_cum.ultimate_ + assert bf_fit_incr.cdf_.equals(bf_fit_cum.cdf_) + assert bf_fit_incr.ultimate_.equals(bf_fit_cum.ultimate_) assert ( bf_fit_cum.full_expectation_ - bf_fit_incr.full_expectation_.incr_to_cum() @@ -2558,7 +2574,7 @@ def test_latest_diagonal_single_origin_ddim_label(raa): def test_latest_diagonal_vs_full_tri_raa(raa): model = cl.Chainladder().fit(raa) - assert model.ultimate_.latest_diagonal == model.full_triangle_.latest_diagonal + assert model.ultimate_.latest_diagonal.equals(model.full_triangle_.latest_diagonal) def test_latest_diagonal_vs_full_tri_clrd(clrd): @@ -2566,7 +2582,9 @@ def test_latest_diagonal_vs_full_tri_clrd(clrd): ult = model.ultimate_ full_tri = model.full_triangle_ - assert np.round(full_tri.latest_diagonal, 0) == np.round(ult.latest_diagonal, 0) + assert np.round(full_tri.latest_diagonal, 0).equals( + np.round(ult.latest_diagonal, 0) + ) def test_semi_annual_grain(): @@ -2706,7 +2724,7 @@ def test_semi_annual_grain(): columns="loss", cumulative=True, ) - assert Atri == Stri.grain("OYDY") + assert Atri.equals(Stri.grain("OYDY")) def test_odd_quarter_end(): @@ -2954,7 +2972,7 @@ def test_triangle_init_from_dict() -> None: cumulative=True, ) - assert tri_from_df == tri_from_dict + assert tri_from_df.equals(tri_from_dict) def test_validate_assumption(raa: Triangle) -> None: @@ -3097,12 +3115,11 @@ def test_validate_assumption_axis2(raa: Triangle) -> None: def test_xs(clrd): # when slicing with .loc on the first term in the index, Triangle will drop the term - assert clrd.xs("Adriatic Ins Co") == clrd.loc["Adriatic Ins Co"] + assert clrd.xs("Adriatic Ins Co").equals(clrd.loc["Adriatic Ins Co"]) assert clrd.xs("Adriatic Ins Co").index.equals(clrd.loc["Adriatic Ins Co"].index) # when slicing with .loc on the all term in the index, Triangle will not drop any term - assert ( - clrd.xs(("Agway Ins Co", "comauto"), drop_level=False) - == clrd.loc["Agway Ins Co", "comauto"] + assert clrd.xs(("Agway Ins Co", "comauto"), drop_level=False).equals( + clrd.loc["Agway Ins Co", "comauto"] ) assert clrd.xs(("Agway Ins Co", "comauto"), drop_level=False).index.equals( clrd.loc["Agway Ins Co", "comauto"].index @@ -3112,15 +3129,14 @@ def test_xs(clrd): cl.load_sample("genins").index ) # when slicing with .loc on the second or subsequent terms in the index, Triangle will not drop the term - assert ( - clrd.xs("comauto", level=1, drop_level=False) - == clrd.loc[clrd["LOB"] == "comauto"] + assert clrd.xs("comauto", level=1, drop_level=False).equals( + clrd.loc[clrd["LOB"] == "comauto"] ) assert clrd.xs("comauto", level=1, drop_level=False).index.equals( clrd.loc[clrd["LOB"] == "comauto"].index ) # level works with either integer index or name of the index column - assert clrd.xs("comauto", level=1) == clrd.xs("comauto", level="LOB") + assert clrd.xs("comauto", level=1).equals(clrd.xs("comauto", level="LOB")) assert clrd.xs("comauto", level=1).index.equals( clrd.xs("comauto", level="LOB").index ) @@ -3561,7 +3577,7 @@ def test_set_backend_roundtrip(raa: Triangle) -> None: assert sparse_raa.array_backend == "sparse" restored = sparse_raa.set_backend("numpy") assert restored.array_backend == "numpy" - assert restored == raa + assert restored.equals(raa) def test_has_zeta_true(raa: Triangle) -> None: @@ -3750,12 +3766,12 @@ def test_json_roundtrip_preserves_dataframe_index(raa, clrd) -> None: r_single = cl.read_json(raa.to_json()) assert isinstance(r_single.index, pd.DataFrame) assert r_single.index.iloc[:, 0].tolist() == ["Total"] - assert r_single == raa + assert r_single.equals(raa) r_multi = cl.read_json(clrd.to_json()) assert isinstance(r_multi.index, pd.DataFrame) pd.testing.assert_frame_equal(r_multi.index, clrd.index) - assert r_multi == clrd + assert r_multi.equals(clrd) def test_triangle_copy_isolated_index(raa) -> None: @@ -3775,7 +3791,7 @@ def test_triangle_index_setter_resets_row_index(raa) -> None: # Boolean Series slicing should work cleanly mask = raa1.index["Total"] == "Total" sliced = raa1[mask] - assert sliced == raa1 + assert sliced.equals(raa1) def test_sort_index_inplace(clrd: Triangle) -> None: @@ -3784,7 +3800,7 @@ def test_sort_index_inplace(clrd: Triangle) -> None: result = shuffled.sort_index(inplace=True) assert result is shuffled pd.testing.assert_frame_equal(shuffled.index, clrd.index) - assert shuffled == clrd + assert shuffled.equals(clrd) def test_duplicate_columns_assignment(raa) -> None: diff --git a/chainladder/development/tests/test_development.py b/chainladder/development/tests/test_development.py index 69d4400f9..b5d33d948 100644 --- a/chainladder/development/tests/test_development.py +++ b/chainladder/development/tests/test_development.py @@ -55,22 +55,28 @@ def fit(self, X, y: None = None, sample_weight: None = None): def test_full_slice(genins): dev1 = cl.Development() dev2 = cl.Development(n_periods=1000) - assert dev1.fit_transform(genins).ldf_ == dev2.fit_transform(genins).ldf_ - assert dev1.fit_transform(genins).ldf_ == _FutureDevelopment(dev1).fit(genins).ldf_ - assert ( + assert dev1.fit_transform(genins).ldf_.equals(dev2.fit_transform(genins).ldf_) + assert dev1.fit_transform(genins).ldf_.equals( _FutureDevelopment(dev1).fit(genins).ldf_ - == _FutureDevelopment(dev2).fit(genins).ldf_ + ) + assert ( + _FutureDevelopment(dev1) + .fit(genins) + .ldf_.equals(_FutureDevelopment(dev2).fit(genins).ldf_) ) def test_full_slice2(genins): dev1 = cl.Development() dev2 = cl.Development(n_periods=[1000] * (genins.shape[3] - 1)) - assert dev1.fit_transform(genins).ldf_ == dev2.fit_transform(genins).ldf_ - assert dev1.fit_transform(genins).ldf_ == _FutureDevelopment(dev1).fit(genins).ldf_ - assert ( + assert dev1.fit_transform(genins).ldf_.equals(dev2.fit_transform(genins).ldf_) + assert dev1.fit_transform(genins).ldf_.equals( _FutureDevelopment(dev1).fit(genins).ldf_ - == _FutureDevelopment(dev2).fit(genins).ldf_ + ) + assert ( + _FutureDevelopment(dev1) + .fit(genins) + .ldf_.equals(_FutureDevelopment(dev2).fit(genins).ldf_) ) @@ -120,7 +126,7 @@ def test_n_periods(): ).flatten() == xp.array([1.164, 1.056, 1.027, 1.012, 1.005, 1.003, 1.002, 1.001, 1.0]) ) - assert dev.fit_transform(d).ldf_ == _FutureDevelopment(dev).fit(d).ldf_ + assert dev.fit_transform(d).ldf_.equals(_FutureDevelopment(dev).fit(d).ldf_) def test_drophighlow(raa): @@ -138,7 +144,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert dev.fit_transform(raa).ldf_ == _FutureDevelopment(dev).fit(raa).ldf_ + assert dev.fit_transform(raa).ldf_.equals(_FutureDevelopment(dev).fit(raa).ldf_) dev = cl.Development(drop_high=[True, False, True, False]) lhs = np.round(dev.fit(raa).cdf_.values, 4).flatten() @@ -154,7 +160,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert dev.fit_transform(raa).ldf_ == _FutureDevelopment(dev).fit(raa).ldf_ + assert dev.fit_transform(raa).ldf_.equals(_FutureDevelopment(dev).fit(raa).ldf_) dev = cl.Development(drop_high=[2, 3, 3, 3], drop_low=[0, 1, 0], preserve=2) tr = dev.fit_transform(raa) @@ -172,7 +178,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert tr.ldf_ == tw.ldf_ + assert tr.ldf_.equals(tw.ldf_) dev = cl.Development(drop_high=1) tr = dev.fit_transform(raa) @@ -190,7 +196,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert tr.ldf_ == tw.ldf_ + assert tr.ldf_.equals(tw.ldf_) dev = cl.Development(drop_high=1, drop_low=1) tr = dev.fit_transform(raa) @@ -208,7 +214,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert tr.ldf_ == tw.ldf_ + assert tr.ldf_.equals(tw.ldf_) dev = cl.Development(drop_high=[2, 1, 1], drop_low=1) tr = dev.fit_transform(raa) @@ -226,7 +232,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert tr.ldf_ == tw.ldf_ + assert tr.ldf_.equals(tw.ldf_) dev = cl.Development(drop_high=1, drop_low=1, n_periods=5) tr = dev.fit_transform(raa) @@ -244,7 +250,7 @@ def test_drophighlow(raa): 1.0092, ]) assert np.all(lhs == rhs) - assert tr.ldf_ == tw.ldf_ + assert tr.ldf_.equals(tw.ldf_) def test_drophighlow_inequal(prism, atol): @@ -298,7 +304,7 @@ def test_dropabove_hardcode1(self, raa: Triangle) -> None: 1.0092, ]) assert np.all(lhs == rhs) - assert model.ldf_ == _FutureDevelopment(dev).fit(raa).ldf_ + assert model.ldf_.equals(_FutureDevelopment(dev).fit(raa).ldf_) def test_dropabove_hardcode2(self, raa: Triangle) -> None: """ @@ -332,7 +338,7 @@ def test_dropabove_hardcode2(self, raa: Triangle) -> None: 1.0092, ]) assert np.all(lhs == rhs) - assert model.ldf_ == future_model.ldf_ + assert model.ldf_.equals(future_model.ldf_) def test_dropabovebelow_hardcode1(self, raa: Triangle) -> None: """ @@ -366,7 +372,7 @@ def test_dropabovebelow_hardcode1(self, raa: Triangle) -> None: 1.0092, ]) assert np.all(lhs == rhs) - assert model.ldf_ == future_model.ldf_ + assert model.ldf_.equals(future_model.ldf_) def test_dropbelow_hardcode_multiple1(self, raa: Triangle) -> None: """ @@ -400,7 +406,7 @@ def test_dropbelow_hardcode_multiple1(self, raa: Triangle) -> None: 1.0092, ]) assert np.all(lhs == rhs) - assert model.ldf_ == future_model.ldf_ + assert model.ldf_.equals(future_model.ldf_) def test_dropbelow_hardcode_multiple2(self, raa: Triangle) -> None: """ @@ -430,24 +436,30 @@ def test_dropbelow_hardcode_multiple2(self, raa: Triangle) -> None: 1.0092, ]) assert np.all(lhs == rhs) - assert model.ldf_ == _FutureDevelopment(dev).fit(raa).ldf_ + assert model.ldf_.equals(_FutureDevelopment(dev).fit(raa).ldf_) def test_drop_valuation_1(raa): dev1 = cl.Development(drop_valuation="1981-12-31") dev2 = cl.Development(drop_valuation="1982-12-31") dev3 = cl.Development(drop_valuation="1983-12-31") - assert dev1.fit_transform(raa).cdf_ != dev2.fit_transform(raa).cdf_ - assert dev2.fit_transform(raa).cdf_ != dev3.fit_transform(raa).cdf_ - assert dev1.fit_transform(raa).cdf_ != dev3.fit_transform(raa).cdf_ + assert not dev1.fit_transform(raa).cdf_.equals(dev2.fit_transform(raa).cdf_) + assert not dev2.fit_transform(raa).cdf_.equals(dev3.fit_transform(raa).cdf_) + assert not dev1.fit_transform(raa).cdf_.equals(dev3.fit_transform(raa).cdf_) assert ( - _FutureDevelopment(dev1).fit(raa).ldf_ != _FutureDevelopment(dev2).fit(raa).ldf_ + not _FutureDevelopment(dev1) + .fit(raa) + .ldf_.equals(_FutureDevelopment(dev2).fit(raa).ldf_) ) assert ( - _FutureDevelopment(dev2).fit(raa).ldf_ != _FutureDevelopment(dev3).fit(raa).ldf_ + not _FutureDevelopment(dev2) + .fit(raa) + .ldf_.equals(_FutureDevelopment(dev3).fit(raa).ldf_) ) assert ( - _FutureDevelopment(dev1).fit(raa).ldf_ != _FutureDevelopment(dev3).fit(raa).ldf_ + not _FutureDevelopment(dev1) + .fit(raa) + .ldf_.equals(_FutureDevelopment(dev3).fit(raa).ldf_) ) @@ -456,37 +468,37 @@ def test_drop_valuation_2(qtr): dev2 = cl.Development(drop_valuation="1995-03-31") dev3 = cl.Development(drop_valuation="1995-06-30") dev4 = cl.Development(drop_valuation="1995-09-30") - assert ( - dev1.fit_transform(qtr["incurred"]).cdf_ - != dev2.fit_transform(qtr["incurred"]).cdf_ - ) - assert ( - dev1.fit_transform(qtr["incurred"]).cdf_ - != dev3.fit_transform(qtr["incurred"]).cdf_ - ) - assert ( + assert not dev1.fit_transform(qtr["incurred"]).cdf_.equals( dev2.fit_transform(qtr["incurred"]).cdf_ - != dev3.fit_transform(qtr["incurred"]).cdf_ ) - assert ( + assert not dev1.fit_transform(qtr["incurred"]).cdf_.equals( dev3.fit_transform(qtr["incurred"]).cdf_ - != dev4.fit_transform(qtr["incurred"]).cdf_ + ) + assert not dev2.fit_transform(qtr["incurred"]).cdf_.equals( + dev3.fit_transform(qtr["incurred"]).cdf_ + ) + assert not dev3.fit_transform(qtr["incurred"]).cdf_.equals( + dev4.fit_transform(qtr["incurred"]).cdf_ ) assert ( - _FutureDevelopment(dev1).fit(qtr["incurred"]).ldf_ - != _FutureDevelopment(dev2).fit(qtr["incurred"]).ldf_ + not _FutureDevelopment(dev1) + .fit(qtr["incurred"]) + .ldf_.equals(_FutureDevelopment(dev2).fit(qtr["incurred"]).ldf_) ) assert ( - _FutureDevelopment(dev1).fit(qtr["incurred"]).ldf_ - != _FutureDevelopment(dev3).fit(qtr["incurred"]).ldf_ + not _FutureDevelopment(dev1) + .fit(qtr["incurred"]) + .ldf_.equals(_FutureDevelopment(dev3).fit(qtr["incurred"]).ldf_) ) assert ( - _FutureDevelopment(dev2).fit(qtr["incurred"]).ldf_ - != _FutureDevelopment(dev3).fit(qtr["incurred"]).ldf_ + not _FutureDevelopment(dev2) + .fit(qtr["incurred"]) + .ldf_.equals(_FutureDevelopment(dev3).fit(qtr["incurred"]).ldf_) ) assert ( - _FutureDevelopment(dev3).fit(qtr["incurred"]).ldf_ - != _FutureDevelopment(dev4).fit(qtr["incurred"]).ldf_ + not _FutureDevelopment(dev3) + .fit(qtr["incurred"]) + .ldf_.equals(_FutureDevelopment(dev4).fit(qtr["incurred"]).ldf_) ) @@ -508,12 +520,18 @@ def test_assymetric_development(qtr, atol): def test_hilo_multiple_indices(clrd): tri = clrd.groupby("LOB")["CumPaidLoss"].sum() assert ( - cl.Development(n_periods=5).fit(tri).ldf_.loc["wkcomp"] - == cl.Development(n_periods=5).fit(tri.loc["wkcomp"]).ldf_ + cl + .Development(n_periods=5) + .fit(tri) + .ldf_.loc["wkcomp"] + .equals(cl.Development(n_periods=5).fit(tri.loc["wkcomp"]).ldf_) ) assert ( - cl.Development(drop_low=2).fit(tri).ldf_.loc["wkcomp"] - == cl.Development(drop_low=2).fit(tri.loc["wkcomp"]).ldf_ + cl + .Development(drop_low=2) + .fit(tri) + .ldf_.loc["wkcomp"] + .equals(cl.Development(drop_low=2).fit(tri.loc["wkcomp"]).ldf_) ) @@ -1017,8 +1035,12 @@ def compare_new_drop(dev, tri): def test_4d_drop(clrd): clrd = clrd.groupby("LOB").sum()[["CumPaidLoss", "IncurLoss"]] assert ( - cl.Development(n_periods=4).fit_transform(clrd.iloc[0, 0]).link_ratio - == cl.Development(n_periods=4).fit_transform(clrd).link_ratio.iloc[0, 0] + cl + .Development(n_periods=4) + .fit_transform(clrd.iloc[0, 0]) + .link_ratio.equals( + cl.Development(n_periods=4).fit_transform(clrd).link_ratio.iloc[0, 0] + ) ) diff --git a/chainladder/methods/tests/test_mack.py b/chainladder/methods/tests/test_mack.py index 82088253c..6d920c760 100644 --- a/chainladder/methods/tests/test_mack.py +++ b/chainladder/methods/tests/test_mack.py @@ -11,11 +11,12 @@ def test_mack_to_triangle(): cl.Development().fit_transform(cl.load_sample("ABC")) ) ) - .summary_ - == cl - .MackChainladder() - .fit(cl.Development().fit_transform(cl.load_sample("ABC"))) - .summary_ + .summary_.equals( + cl + .MackChainladder() + .fit(cl.Development().fit_transform(cl.load_sample("ABC"))) + .summary_ + ) ) @@ -23,7 +24,7 @@ def test_mack_malformed(raa): raa_alt = raa.copy().iloc[:, :, :-1] x = cl.MackChainladder().fit(raa) y = cl.MackChainladder().fit(raa_alt) - assert x.process_risk_.iloc[:, :, :-1] == y.process_risk_ + assert x.process_risk_.iloc[:, :, :-1].equals(y.process_risk_) def test_multi_triangle_mack(clrd, atol): diff --git a/chainladder/methods/tests/test_predict.py b/chainladder/methods/tests/test_predict.py index 17f44f9c3..d11748cfe 100644 --- a/chainladder/methods/tests/test_predict.py +++ b/chainladder/methods/tests/test_predict.py @@ -378,19 +378,19 @@ def test_align_cdfs(raa): raa.dev_to_val().iloc[..., :4, -1].val_to_dev(), sample_weight=ld.iloc[..., :4, :], ).ultimate_ - assert a == b + assert a.equals(b) model = cl.Chainladder().fit(raa, sample_weight=ld) a = model.ultimate_.iloc[..., :4, :] b = model.predict( raa.dev_to_val().iloc[..., :4, -1].val_to_dev(), sample_weight=ld.iloc[..., :4, :], ).ultimate_ - assert a == b + assert a.equals(b) def test_check_val_tri_cl(raa): model = cl.Chainladder().fit(raa.dev_to_val()) - assert model.predict(raa.latest_diagonal).ultimate_ == model.ultimate_ + assert model.predict(raa.latest_diagonal).ultimate_.equals(model.ultimate_) def test_odd_shaped_triangle(): diff --git a/chainladder/utils/tests/test_tri_w.py b/chainladder/utils/tests/test_tri_w.py index 8f075b411..213654101 100644 --- a/chainladder/utils/tests/test_tri_w.py +++ b/chainladder/utils/tests/test_tri_w.py @@ -18,7 +18,7 @@ def test_triangleweight_full_triangle(self, raa: Triangle) -> None: ult = cl.Chainladder().fit(raa) tw = cl.TriangleWeight(n_periods=4).fit(raa) tw_full = cl.TriangleWeight(n_periods=4).fit(ult.full_triangle_) - assert tw.w_.iloc[:, :, :, 0] == tw_full.w_.iloc[:, :, :, 0] + assert tw.w_.iloc[:, :, :, 0].equals(tw_full.w_.iloc[:, :, :, 0]) def test_triangleweight_full_irregular_triangle(self) -> None: """ @@ -28,4 +28,4 @@ def test_triangleweight_full_irregular_triangle(self) -> None: ult = cl.Chainladder().fit(prism) tw = cl.TriangleWeight(n_periods=4).fit(prism) tw_full = cl.TriangleWeight(n_periods=4).fit(ult.full_triangle_) - assert tw.w_.iloc[:, :, :, 0] == tw_full.w_.iloc[:, :, :, 0] + assert tw.w_.iloc[:, :, :, 0].equals(tw_full.w_.iloc[:, :, :, 0]) diff --git a/chainladder/utils/tests/test_utilities.py b/chainladder/utils/tests/test_utilities.py index ae355634e..86b40fd86 100644 --- a/chainladder/utils/tests/test_utilities.py +++ b/chainladder/utils/tests/test_utilities.py @@ -58,7 +58,7 @@ def from_sequence(seq): def test_triangle_json_io(clrd): clrd2 = cl.read_json(clrd.to_json(), array_backend=clrd.array_backend) - assert clrd == clrd2 + assert clrd.equals(clrd2) assert clrd.index.equals(clrd2.index) assert np.all(clrd.columns == clrd2.columns) assert np.all(clrd.odims == clrd2.odims) @@ -68,7 +68,7 @@ def test_triangle_json_io(clrd): def test_json_for_val(raa): x = raa.dev_to_val().to_json() - assert cl.read_json(x) == raa.dev_to_val() + assert cl.read_json(x).equals(raa.dev_to_val()) def test_estimator_json_io(): @@ -108,13 +108,15 @@ def test_read_csv_single(raa): raa_csv_path = Path(__file__).parent.parent / "data" / "raa.csv" - assert raa == cl.read_csv( - filepath_or_buffer=raa_csv_path, - origin="origin", - valuation="development", - columns=["values"], - index=None, - cumulative=True, + assert raa.equals( + cl.read_csv( + filepath_or_buffer=raa_csv_path, + origin="origin", + valuation="development", + columns=["values"], + index=None, + cumulative=True, + ) ) @@ -125,28 +127,29 @@ def test_read_csv_multi(clrd): clrd_csv_path = Path(__file__).parent.parent / "data" / "clrd.csv" - assert clrd == cl.read_csv( - filepath_or_buffer=clrd_csv_path, - origin="AccidentYear", - valuation="DevelopmentYear", - columns=[ - "IncurLoss", - "CumPaidLoss", - "BulkLoss", - "EarnedPremDIR", - "EarnedPremCeded", - "EarnedPremNet", - ], - index=["GRNAME", "LOB"], - cumulative=True, + assert clrd.equals( + cl.read_csv( + filepath_or_buffer=clrd_csv_path, + origin="AccidentYear", + valuation="DevelopmentYear", + columns=[ + "IncurLoss", + "CumPaidLoss", + "BulkLoss", + "EarnedPremDIR", + "EarnedPremCeded", + "EarnedPremNet", + ], + index=["GRNAME", "LOB"], + cumulative=True, + ) ) def test_concat(clrd): tri = clrd.groupby("LOB").sum() - assert ( - cl.concat([tri.loc["wkcomp"], tri.loc["comauto"]], axis=0) - == tri.loc[["wkcomp", "comauto"]] + assert cl.concat([tri.loc["wkcomp"], tri.loc["comauto"]], axis=0).equals( + tri.loc[["wkcomp", "comauto"]] ) @@ -207,7 +210,7 @@ def test_concat_immutability(raa): u.columns = latest.columns u_new = copy.deepcopy(u) cl.concat((latest, u), axis=3) - assert u == u_new + assert u.equals(u_new) def test_to_pickle_read_pickle(raa): @@ -437,7 +440,7 @@ def test_read_pickle_triangle(raa: Triangle, tmp_path: Path) -> None: pkl_path = tmp_path / "triangle.pkl" with open(pkl_path, "wb") as f: dill.dump(raa, f) - assert cl.read_pickle(str(pkl_path)) == raa + assert cl.read_pickle(str(pkl_path)).equals(raa) def test_triangle_to_pickle(raa: Triangle, clrd: Triangle, tmp_path: Path) -> None: @@ -463,13 +466,13 @@ def test_triangle_to_pickle(raa: Triangle, clrd: Triangle, tmp_path: Path) -> No raa_path = tmp_path / "raa.pkl" raa.to_pickle(str(raa_path)) assert raa_path.is_file() - assert cl.read_pickle(str(raa_path)) == raa + assert cl.read_pickle(str(raa_path)).equals(raa) # Multidimensional case. clrd_path = tmp_path / "clrd.pkl" clrd.to_pickle(str(clrd_path)) assert clrd_path.is_file() - assert cl.read_pickle(str(clrd_path)) == clrd + assert cl.read_pickle(str(clrd_path)).equals(clrd) def test_read_pickle_estimator(raa: Triangle, tmp_path: Path) -> None: @@ -494,7 +497,7 @@ def test_read_pickle_estimator(raa: Triangle, tmp_path: Path) -> None: dev = cl.Development().fit(raa) with open(pkl_path, "wb") as f: dill.dump(dev, f) - assert dev.ldf_ == cl.read_pickle(str(pkl_path)).ldf_ + assert dev.ldf_.equals(cl.read_pickle(str(pkl_path)).ldf_) def test_concat_type_error() -> None: diff --git a/chainladder/workflow/tests/test_voting.py b/chainladder/workflow/tests/test_voting.py index c748daeb1..d04abd064 100644 --- a/chainladder/workflow/tests/test_voting.py +++ b/chainladder/workflow/tests/test_voting.py @@ -206,7 +206,9 @@ def test_tri_sel(clrd: Triangle) -> None: starter test for the TriangleSelector class """ tri = clrd.sum() - assert tri["CumPaidLoss"] == cl.TriangleSelector("CumPaidLoss").fit_transform(tri) + assert tri["CumPaidLoss"].equals( + cl.TriangleSelector("CumPaidLoss").fit_transform(tri) + ) def test_mismatching_tri_sel(clrd: Triangle) -> None: From 74ff94e0f88f421d429f17bc4200c7f4ca30faf1 Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 06:00:04 -0500 Subject: [PATCH 2/6] Sort imports in the changed test files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply ruff's import sorting (rule I) to the test files changed in the previous commit, as the Ruff workflow suggests for changed files. Developed with an AI assistant (Árbol, running Muse). --- .../adjustments/tests/test_berqsherm.py | 3 ++- .../adjustments/tests/test_disposal.py | 5 +++-- chainladder/adjustments/tests/test_trend.py | 3 ++- chainladder/core/tests/test_grain.py | 5 +++-- chainladder/core/tests/test_slicing.py | 4 ++-- chainladder/core/tests/test_triangle.py | 4 +++- .../development/tests/test_development.py | 6 ++++-- chainladder/methods/tests/test_mack.py | 3 ++- chainladder/methods/tests/test_predict.py | 3 ++- chainladder/utils/tests/test_tri_w.py | 4 ++-- chainladder/utils/tests/test_utilities.py | 21 ++++++++++--------- chainladder/workflow/tests/test_voting.py | 5 +++-- 12 files changed, 39 insertions(+), 27 deletions(-) diff --git a/chainladder/adjustments/tests/test_berqsherm.py b/chainladder/adjustments/tests/test_berqsherm.py index 9608d5956..01835672a 100644 --- a/chainladder/adjustments/tests/test_berqsherm.py +++ b/chainladder/adjustments/tests/test_berqsherm.py @@ -1,6 +1,7 @@ -import chainladder as cl import numpy as np +import chainladder as cl + def test_preserve_diagonal(): triangle = cl.load_sample("berqsherm").loc["Auto"] diff --git a/chainladder/adjustments/tests/test_disposal.py b/chainladder/adjustments/tests/test_disposal.py index 1bc50e159..7ada7d641 100644 --- a/chainladder/adjustments/tests/test_disposal.py +++ b/chainladder/adjustments/tests/test_disposal.py @@ -1,10 +1,11 @@ from __future__ import annotations -import chainladder as cl +from typing import TYPE_CHECKING + import numpy as np import pytest -from typing import TYPE_CHECKING +import chainladder as cl if TYPE_CHECKING: from chainladder.core import Triangle diff --git a/chainladder/adjustments/tests/test_trend.py b/chainladder/adjustments/tests/test_trend.py index 855a6a57f..ea9f503da 100644 --- a/chainladder/adjustments/tests/test_trend.py +++ b/chainladder/adjustments/tests/test_trend.py @@ -1,6 +1,7 @@ -import chainladder as cl import numpy as np +import chainladder as cl + def test_trend1(clrd): tri = clrd[["CumPaidLoss", "EarnedPremDIR"]].sum() diff --git a/chainladder/core/tests/test_grain.py b/chainladder/core/tests/test_grain.py index ddda6261b..e371413eb 100644 --- a/chainladder/core/tests/test_grain.py +++ b/chainladder/core/tests/test_grain.py @@ -1,10 +1,11 @@ from __future__ import annotations -import chainladder as cl +from typing import TYPE_CHECKING + import numpy as np import pytest -from typing import TYPE_CHECKING +import chainladder as cl if TYPE_CHECKING: from chainladder import Triangle diff --git a/chainladder/core/tests/test_slicing.py b/chainladder/core/tests/test_slicing.py index 3a06b0fd4..a58485ccb 100644 --- a/chainladder/core/tests/test_slicing.py +++ b/chainladder/core/tests/test_slicing.py @@ -1,12 +1,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np import pytest import chainladder as cl -from typing import TYPE_CHECKING - if TYPE_CHECKING: from chainladder import Triangle diff --git a/chainladder/core/tests/test_triangle.py b/chainladder/core/tests/test_triangle.py index 9f76e4bed..9c9197b91 100644 --- a/chainladder/core/tests/test_triangle.py +++ b/chainladder/core/tests/test_triangle.py @@ -4,16 +4,18 @@ import io import pickle import warnings + from io import StringIO from typing import TYPE_CHECKING -import chainladder as cl import matplotlib import matplotlib.pyplot as plt import numpy as np import pandas as pd import pytest +import chainladder as cl + from chainladder.core.axis import ( TriangleAxis, _set_columns, diff --git a/chainladder/development/tests/test_development.py b/chainladder/development/tests/test_development.py index b5d33d948..4e3086a1a 100644 --- a/chainladder/development/tests/test_development.py +++ b/chainladder/development/tests/test_development.py @@ -1,11 +1,13 @@ from __future__ import annotations import warnings + +from typing import TYPE_CHECKING + import numpy as np -import chainladder as cl import pytest -from typing import TYPE_CHECKING +import chainladder as cl if TYPE_CHECKING: from chainladder import Triangle diff --git a/chainladder/methods/tests/test_mack.py b/chainladder/methods/tests/test_mack.py index 6d920c760..9e9bfb9a0 100644 --- a/chainladder/methods/tests/test_mack.py +++ b/chainladder/methods/tests/test_mack.py @@ -1,6 +1,7 @@ -import chainladder as cl import numpy as np +import chainladder as cl + def test_mack_to_triangle(): assert ( diff --git a/chainladder/methods/tests/test_predict.py b/chainladder/methods/tests/test_predict.py index d11748cfe..85ff7a015 100644 --- a/chainladder/methods/tests/test_predict.py +++ b/chainladder/methods/tests/test_predict.py @@ -1,8 +1,9 @@ -import chainladder as cl import numpy as np import pandas as pd import pytest +import chainladder as cl + raa = cl.load_sample("RAA") raa_1989 = raa[raa.valuation < raa.valuation_date] cl_ult = cl.Chainladder().fit(raa).ultimate_ # Chainladder Ultimate diff --git a/chainladder/utils/tests/test_tri_w.py b/chainladder/utils/tests/test_tri_w.py index 213654101..97d609aa4 100644 --- a/chainladder/utils/tests/test_tri_w.py +++ b/chainladder/utils/tests/test_tri_w.py @@ -1,9 +1,9 @@ from __future__ import annotations -import chainladder as cl - from typing import TYPE_CHECKING +import chainladder as cl + if TYPE_CHECKING: from chainladder import Triangle diff --git a/chainladder/utils/tests/test_utilities.py b/chainladder/utils/tests/test_utilities.py index 86b40fd86..041073152 100644 --- a/chainladder/utils/tests/test_utilities.py +++ b/chainladder/utils/tests/test_utilities.py @@ -1,13 +1,17 @@ from __future__ import annotations -import pytest - -import chainladder as cl import copy -import dill import warnings + +from pathlib import Path +from typing import TYPE_CHECKING + +import dill import numpy as np import pandas as pd +import pytest + +import chainladder as cl from chainladder import __dt64_unit__ from chainladder.utils.data._manifest import SAMPLES @@ -17,12 +21,9 @@ minimum, ) -from pathlib import Path -from typing import TYPE_CHECKING - if TYPE_CHECKING: - from pytest import CaptureFixture - from pytest import MonkeyPatch + from pytest import CaptureFixture, MonkeyPatch + from chainladder import Triangle @@ -214,8 +215,8 @@ def test_concat_immutability(raa): def test_to_pickle_read_pickle(raa): - import tempfile import os + import tempfile dev = cl.Development(average="simple", n_periods=4).fit(raa) fd, path = tempfile.mkstemp(suffix=".pkl") diff --git a/chainladder/workflow/tests/test_voting.py b/chainladder/workflow/tests/test_voting.py index d04abd064..3f4ef9083 100644 --- a/chainladder/workflow/tests/test_voting.py +++ b/chainladder/workflow/tests/test_voting.py @@ -1,10 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import numpy as np -import chainladder as cl import pytest -from typing import TYPE_CHECKING +import chainladder as cl if TYPE_CHECKING: from chainladder import Triangle From 36c5e16f7d0538edcb211797e4d2baa34b4df12e Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 06:06:25 -0500 Subject: [PATCH 3/6] Use Triangle.equals in the docs notebooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the whole-triangle == comparisons in the tutorial and user guide notebooks with Triangle.equals. The docs build executes every notebook, so these comparisons warn there. Six of the edited cells stored np.True_ as their output; re-running them gives True, the Python bool that equals returns, and the stored outputs now match. Part of #1395. Developed with an AI assistant (Árbol, running Muse). --- .../tutorials/deterministic-tutorial.ipynb | 4 ++-- .../tutorials/development-tutorial.ipynb | 14 ++++++++------ .../tutorials/stochastic-tutorial.ipynb | 8 ++++---- .../tutorials/triangle-tutorial.ipynb | 4 ++-- docs/user_guide/development.ipynb | 10 ++++++---- docs/user_guide/tails.ipynb | 5 ++--- docs/user_guide/triangle.ipynb | 16 ++++++++-------- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/docs/getting_started/tutorials/deterministic-tutorial.ipynb b/docs/getting_started/tutorials/deterministic-tutorial.ipynb index 655623371..69db419ef 100644 --- a/docs/getting_started/tutorials/deterministic-tutorial.ipynb +++ b/docs/getting_started/tutorials/deterministic-tutorial.ipynb @@ -3494,7 +3494,7 @@ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 20, @@ -3512,7 +3512,7 @@ " sample_weight=0.75 * comauto[\"EarnedPremNet\"].latest_diagonal,\n", ")\n", "\n", - "b1.ultimate_ == b2.ultimate_" + "b1.ultimate_.equals(b2.ultimate_)" ] }, { diff --git a/docs/getting_started/tutorials/development-tutorial.ipynb b/docs/getting_started/tutorials/development-tutorial.ipynb index 370c9f738..f971bf193 100644 --- a/docs/getting_started/tutorials/development-tutorial.ipynb +++ b/docs/getting_started/tutorials/development-tutorial.ipynb @@ -1767,15 +1767,15 @@ } }, "source": [ - "cl.Development(n_periods=[1, 2, 3, 4, 5, 6, 7, 8, 9]).fit(\n", - " genins\n", - ").ldf_ == cl.Development(n_periods=[1, 2, 3, 4, 5, 4, 3, 2, 1]).fit(genins).ldf_" + "cl.Development(n_periods=[1, 2, 3, 4, 5, 6, 7, 8, 9]).fit(genins).ldf_.equals(\n", + " cl.Development(n_periods=[1, 2, 3, 4, 5, 4, 3, 2, 1]).fit(genins).ldf_\n", + ")" ], "outputs": [ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 22, @@ -3331,13 +3331,15 @@ } }, "source": [ - "cl.Development().fit_transform(genins) == cl.Development().fit(genins).transform(genins)" + "cl.Development().fit_transform(genins).equals(\n", + " cl.Development().fit(genins).transform(genins)\n", + ")" ], "outputs": [ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 36, diff --git a/docs/getting_started/tutorials/stochastic-tutorial.ipynb b/docs/getting_started/tutorials/stochastic-tutorial.ipynb index 8ec8bb3d2..7d5dc508a 100644 --- a/docs/getting_started/tutorials/stochastic-tutorial.ipynb +++ b/docs/getting_started/tutorials/stochastic-tutorial.ipynb @@ -76,7 +76,7 @@ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 2, @@ -93,9 +93,9 @@ " .loc[\"wkcomp\", [\"CumPaidLoss\", \"EarnedPremNet\"]]\n", ")\n", "\n", - "cl.Chainladder().fit(clrd[\"CumPaidLoss\"]).ultimate_ == cl.MackChainladder().fit(\n", - " clrd[\"CumPaidLoss\"]\n", - ").ultimate_" + "cl.Chainladder().fit(clrd[\"CumPaidLoss\"]).ultimate_.equals(\n", + " cl.MackChainladder().fit(clrd[\"CumPaidLoss\"]).ultimate_\n", + ")" ] }, { diff --git a/docs/getting_started/tutorials/triangle-tutorial.ipynb b/docs/getting_started/tutorials/triangle-tutorial.ipynb index 4e73a1c40..acc7e34fa 100644 --- a/docs/getting_started/tutorials/triangle-tutorial.ipynb +++ b/docs/getting_started/tutorials/triangle-tutorial.ipynb @@ -13321,8 +13321,8 @@ } ], "source": [ - "print(\"Commutative?\", prism.sum().latest_diagonal == prism.latest_diagonal.sum())\n", - "print(\"Commutative?\", prism.loc[\"Home\"].link_ratio == prism.link_ratio.loc[\"Home\"])" + "print(\"Commutative?\", prism.sum().latest_diagonal.equals(prism.latest_diagonal.sum()))\n", + "print(\"Commutative?\", prism.loc[\"Home\"].link_ratio.equals(prism.link_ratio.loc[\"Home\"]))" ] }, { diff --git a/docs/user_guide/development.ipynb b/docs/user_guide/development.ipynb index fef6058d5..4a00c3401 100644 --- a/docs/user_guide/development.ipynb +++ b/docs/user_guide/development.ipynb @@ -210,7 +210,7 @@ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 3, @@ -220,7 +220,7 @@ ], "source": [ "dev = cl.Development().fit(cl.load_sample(\"raa\"))\n", - "dev.ldf_.incr_to_cum() == dev.cdf_" + "dev.ldf_.incr_to_cum().equals(dev.cdf_)" ] }, { @@ -5561,7 +5561,7 @@ { "data": { "text/plain": [ - "np.True_" + "True" ] }, "execution_count": 23, @@ -5570,7 +5570,9 @@ } ], "source": [ - "zeta_.loc[..., 72] * tri[\"exposure\"].latest_diagonal == ia.incremental_.loc[..., 72]" + "(zeta_.loc[..., 72] * tri[\"exposure\"].latest_diagonal).equals(\n", + " ia.incremental_.loc[..., 72]\n", + ")" ] }, { diff --git a/docs/user_guide/tails.ipynb b/docs/user_guide/tails.ipynb index 7c282f735..e266afafe 100644 --- a/docs/user_guide/tails.ipynb +++ b/docs/user_guide/tails.ipynb @@ -1011,9 +1011,8 @@ } ], "source": [ - "(\n", - " cl.TailCurve(fit_period=[False] * 11 + [True] * 33).fit(dev).cdf_\n", - " == cl.TailCurve(fit_period=(36, None)).fit(dev).cdf_\n", + "cl.TailCurve(fit_period=[False] * 11 + [True] * 33).fit(dev).cdf_.equals(\n", + " cl.TailCurve(fit_period=(36, None)).fit(dev).cdf_\n", ")" ] }, diff --git a/docs/user_guide/triangle.ipynb b/docs/user_guide/triangle.ipynb index 5c35d5186..8afb68ddc 100644 --- a/docs/user_guide/triangle.ipynb +++ b/docs/user_guide/triangle.ipynb @@ -1905,12 +1905,12 @@ "source": [ "tri = cl.load_sample(\"quarterly\")\n", "# Functionally equivalent transformations\n", - "tri.grain(\"OYDY\").val_to_dev() == tri.val_to_dev().grain(\"OYDY\")\n", - "tri.cum_to_incr().grain(\"OYDY\").val_to_dev() == tri.val_to_dev().cum_to_incr().grain(\n", - " \"OYDY\"\n", + "tri.grain(\"OYDY\").val_to_dev().equals(tri.val_to_dev().grain(\"OYDY\"))\n", + "tri.cum_to_incr().grain(\"OYDY\").val_to_dev().equals(\n", + " tri.val_to_dev().cum_to_incr().grain(\"OYDY\")\n", ")\n", - "tri.grain(\"OYDY\").cum_to_incr().val_to_dev().incr_to_cum() == tri.val_to_dev().grain(\n", - " \"OYDY\"\n", + "tri.grain(\"OYDY\").cum_to_incr().val_to_dev().incr_to_cum().equals(\n", + " tri.val_to_dev().grain(\"OYDY\")\n", ")" ] }, @@ -2869,7 +2869,7 @@ "source": [ "s1 = cl.load_sample(\"clrd\").iloc[:3]\n", "s2 = s1.sort_index(ascending=False)\n", - "s1 + s2 == 2 * s1" + "(s1 + s2).equals(2 * s1)" ] }, { @@ -2890,7 +2890,7 @@ } ], "source": [ - "s1 + s2.values == 2 * s1" + "(s1 + s2.values).equals(2 * s1)" ] }, { @@ -2912,7 +2912,7 @@ ], "source": [ "s3 = s1.iloc[:, ::-1]\n", - "s1 + s3 == 2 * s1" + "(s1 + s3).equals(2 * s1)" ] }, { From 2cbbb45811c6ee86f07e0c1d70c1ae499c81ef16 Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 07:11:52 -0500 Subject: [PATCH 4/6] Use Triangle.equals in the io docstring examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The to_pickle and to_json docstrings each compare the restored triangle with the original using ==, in a testcode block that the Doctest job runs, so both emit the FutureWarning on every docs build. Both now call equals. The expected output stays True, since equals returns a Python bool. Part of #1395. Developed with an AI assistant (Árbol, running Muse). --- chainladder/core/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chainladder/core/io.py b/chainladder/core/io.py index c41d7f16b..77319061f 100644 --- a/chainladder/core/io.py +++ b/chainladder/core/io.py @@ -44,7 +44,7 @@ def to_pickle(self, path, protocol=None): restored = cl.read_pickle(path) os.remove(path) print(restored.shape) - print(restored == raa) + print(restored.equals(raa)) .. testoutput:: @@ -78,7 +78,7 @@ def to_json(self): raa = cl.load_sample('raa') payload = json.loads(raa.to_json()) print(sorted(payload.keys())) - print(cl.read_json(raa.to_json()) == raa) + print(cl.read_json(raa.to_json()).equals(raa)) .. testoutput:: From 741689739d6f1980fe341ae7b83c8bdbc4da31ae Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 07:37:38 -0500 Subject: [PATCH 5/6] Sort imports in core/io.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply ruff's import sorting (rule I) to io.py, which the previous commit changed, as the Ruff workflow suggests for changed files. Developed with an AI assistant (Árbol, running Muse). --- chainladder/core/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chainladder/core/io.py b/chainladder/core/io.py index 77319061f..d57ed034a 100644 --- a/chainladder/core/io.py +++ b/chainladder/core/io.py @@ -5,8 +5,9 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. -import dill import json + +import dill import pandas as pd from sklearn.base import BaseEstimator From 5e7e8949b5a689426e5baf6c75bf3bdc05847d17 Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Thu, 5 Nov 2026 11:02:29 -0500 Subject: [PATCH 6/6] Sort imports in the docs notebooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply ruff's import sorting (rule I) to the import cells of the seven docs notebooks this PR changes, as the Ruff workflow suggests for changed files. Each cell keeps its statements; only the order of the imports and the blank lines between import groups change. Developed with an AI assistant (Árbol, running Muse). --- .../getting_started/tutorials/deterministic-tutorial.ipynb | 5 +++-- docs/getting_started/tutorials/development-tutorial.ipynb | 3 ++- docs/getting_started/tutorials/stochastic-tutorial.ipynb | 7 ++++--- docs/getting_started/tutorials/triangle-tutorial.ipynb | 3 ++- docs/user_guide/development.ipynb | 7 ++++--- docs/user_guide/tails.ipynb | 7 ++++--- docs/user_guide/triangle.ipynb | 4 ++-- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/getting_started/tutorials/deterministic-tutorial.ipynb b/docs/getting_started/tutorials/deterministic-tutorial.ipynb index 69db419ef..f28c35c97 100644 --- a/docs/getting_started/tutorials/deterministic-tutorial.ipynb +++ b/docs/getting_started/tutorials/deterministic-tutorial.ipynb @@ -32,10 +32,11 @@ } ], "source": [ - "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", "import numpy as np\n", + "import pandas as pd\n", + "\n", "import chainladder as cl\n", - "import matplotlib.pyplot as plt\n", "\n", "print(\"pandas: \" + pd.__version__)\n", "print(\"numpy: \" + np.__version__)\n", diff --git a/docs/getting_started/tutorials/development-tutorial.ipynb b/docs/getting_started/tutorials/development-tutorial.ipynb index f971bf193..ddad15973 100644 --- a/docs/getting_started/tutorials/development-tutorial.ipynb +++ b/docs/getting_started/tutorials/development-tutorial.ipynb @@ -20,8 +20,9 @@ } }, "source": [ - "import pandas as pd\n", "import numpy as np\n", + "import pandas as pd\n", + "\n", "import chainladder as cl\n", "\n", "print(\"pandas: \" + pd.__version__)\n", diff --git a/docs/getting_started/tutorials/stochastic-tutorial.ipynb b/docs/getting_started/tutorials/stochastic-tutorial.ipynb index 7d5dc508a..3ee2f26ce 100644 --- a/docs/getting_started/tutorials/stochastic-tutorial.ipynb +++ b/docs/getting_started/tutorials/stochastic-tutorial.ipynb @@ -32,12 +32,13 @@ } ], "source": [ - "import pandas as pd\n", - "import numpy as np\n", - "import chainladder as cl\n", "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", "import statsmodels.api as sm\n", "\n", + "import chainladder as cl\n", + "\n", "print(\"pandas: \" + pd.__version__)\n", "print(\"numpy: \" + np.__version__)\n", "print(\"chainladder: \" + cl.__version__)" diff --git a/docs/getting_started/tutorials/triangle-tutorial.ipynb b/docs/getting_started/tutorials/triangle-tutorial.ipynb index acc7e34fa..b434918fb 100644 --- a/docs/getting_started/tutorials/triangle-tutorial.ipynb +++ b/docs/getting_started/tutorials/triangle-tutorial.ipynb @@ -44,8 +44,9 @@ } ], "source": [ - "import pandas as pd\n", "import numpy as np\n", + "import pandas as pd\n", + "\n", "import chainladder as cl\n", "\n", "print(\"pandas: \" + pd.__version__)\n", diff --git a/docs/user_guide/development.ipynb b/docs/user_guide/development.ipynb index 4a00c3401..696d26a5c 100644 --- a/docs/user_guide/development.ipynb +++ b/docs/user_guide/development.ipynb @@ -152,9 +152,10 @@ "metadata": {}, "outputs": [], "source": [ - "import chainladder as cl\n", - "import pandas as pd\n", "import matplotlib.pyplot as plt\n", + "import pandas as pd\n", + "\n", + "import chainladder as cl\n", "\n", "plt.style.use(\"ggplot\")\n", "%config InlineBackend.figure_format = 'retina'" @@ -7256,10 +7257,10 @@ } ], "source": [ + "from sklearn.compose import ColumnTransformer\n", "from sklearn.ensemble import RandomForestRegressor\n", "from sklearn.pipeline import Pipeline\n", "from sklearn.preprocessing import OneHotEncoder\n", - "from sklearn.compose import ColumnTransformer\n", "\n", "clrd = cl.load_sample(\"clrd\").groupby(\"LOB\").sum()[\"CumPaidLoss\"]\n", "\n", diff --git a/docs/user_guide/tails.ipynb b/docs/user_guide/tails.ipynb index e266afafe..92541373a 100644 --- a/docs/user_guide/tails.ipynb +++ b/docs/user_guide/tails.ipynb @@ -24,10 +24,11 @@ }, "outputs": [], "source": [ - "import chainladder as cl\n", - "import pandas as pd\n", - "import numpy as np\n", "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "\n", + "import chainladder as cl\n", "\n", "plt.style.use(\"ggplot\")\n", "%config InlineBackend.figure_format = 'retina'" diff --git a/docs/user_guide/triangle.ipynb b/docs/user_guide/triangle.ipynb index 8afb68ddc..e60a23afc 100644 --- a/docs/user_guide/triangle.ipynb +++ b/docs/user_guide/triangle.ipynb @@ -22,10 +22,10 @@ "metadata": {}, "outputs": [], "source": [ - "import chainladder as cl\n", + "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "\n", - "import matplotlib.pyplot as plt\n", + "import chainladder as cl\n", "\n", "plt.style.use(\"ggplot\")\n", "%config InlineBackend.figure_format = 'retina'"