From 3edb51d3f03cd4e0e9c9648c56d01f01780d60ec Mon Sep 17 00:00:00 2001 From: Gene Dan Date: Fri, 4 Sep 2026 21:30:28 -0500 Subject: [PATCH] [FIX] Apply Ruff fix to rtest files. --- chainladder/core/tests/rtest_correlation.py | 16 ++++++---- chainladder/development/tests/rtest_clark.py | 15 ++++++---- .../development/tests/rtest_development.py | 13 ++++----- chainladder/development/tests/rtest_munich.py | 14 ++++----- chainladder/methods/tests/rtest_mack.py | 29 ++++++++++++++----- chainladder/tails/tests/rtest_exponential.py | 6 ++-- pyproject.toml | 6 ---- 7 files changed, 57 insertions(+), 42 deletions(-) diff --git a/chainladder/core/tests/rtest_correlation.py b/chainladder/core/tests/rtest_correlation.py index 206306667..3f452078e 100644 --- a/chainladder/core/tests/rtest_correlation.py +++ b/chainladder/core/tests/rtest_correlation.py @@ -1,7 +1,7 @@ -### Building out a dev environment with a working copy -### of R ChainLadder is difficult. These tests are -### Currently inactive, but available should the compatibility -### of the installs improve at a later date. +# Building out a dev environment with a working copy +# of R ChainLadder is difficult. These tests are +# Currently inactive, but available should the compatibility +# of the installs improve at a later date. import numpy as np import pytest @@ -10,14 +10,20 @@ try: from rpy2.robjects.packages import importr from rpy2.robjects import r + CL = importr("ChainLadder") -except: +except ImportError: pass + def dev_corr_r(data, ci): return r("out<-dfCorTest({},ci={})".format(data, ci)) +def dev_corr_p(data, ci): + return cl.load_sample(data).development_correlation(p_critical=ci) + + @pytest.mark.r def val_corr_r(data, ci): return r("out<-cyEffTest({},ci={})".format(data, ci)) diff --git a/chainladder/development/tests/rtest_clark.py b/chainladder/development/tests/rtest_clark.py index ff2229f72..902125d8a 100644 --- a/chainladder/development/tests/rtest_clark.py +++ b/chainladder/development/tests/rtest_clark.py @@ -1,7 +1,7 @@ -### Building out a dev environment with a working copy -### of R ChainLadder is difficult. These tests are -### Currently inactive, but available should the compatibility -### of the installs improve at a later date. +# Building out a dev environment with a working copy +# of R ChainLadder is difficult. These tests are +# Currently inactive, but available should the compatibility +# of the installs improve at a later date. import numpy as np import chainladder as cl @@ -10,10 +10,12 @@ try: from rpy2.robjects.packages import importr from rpy2.robjects import r + CL = importr("ChainLadder") -except: +except ImportError: pass + @pytest.mark.r def test_clarkldf(genins): model = cl.ClarkLDF().fit(genins) @@ -23,6 +25,7 @@ def test_clarkldf(genins): assert abs(model.omega_.iloc[0, 0] - r_omega) < 1e-2 assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2 + @pytest.mark.r def test_clarkldf_weibull(genins): model = cl.ClarkLDF(growth="weibull").fit(genins) @@ -32,6 +35,7 @@ def test_clarkldf_weibull(genins): assert abs(model.omega_.iloc[0, 0] - r_omega) < 1e-2 assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2 + @pytest.mark.r def test_clarkcapecod(genins): df = r("ClarkCapeCod(GenIns, Premium=10000000+400000*0:9)") @@ -45,6 +49,7 @@ def test_clarkcapecod(genins): assert abs(model.theta_.iloc[0, 0] / 12 - r_theta) < 1e-2 assert abs(model.elr_.iloc[0, 0] - r_elr) < 1e-2 + @pytest.mark.r def test_clarkcapcod_weibull(genins): df = r('ClarkCapeCod(GenIns, Premium=10000000+400000*0:9, G="weibull")') diff --git a/chainladder/development/tests/rtest_development.py b/chainladder/development/tests/rtest_development.py index 30960bfa6..b0f9cf644 100644 --- a/chainladder/development/tests/rtest_development.py +++ b/chainladder/development/tests/rtest_development.py @@ -1,9 +1,8 @@ -### Building out a dev environment with a working copy -### of R ChainLadder is difficult. These tests are -### Currently inactive, but available should the compatibility -### of the installs improve at a later date. +# Building out a dev environment with a working copy +# of R ChainLadder is difficult. These tests are +# Currently inactive, but available should the compatibility +# of the installs improve at a later date. -import numpy as np import pytest import chainladder as cl @@ -12,7 +11,7 @@ from rpy2.robjects import r CL = importr("ChainLadder") -except: +except ImportError: pass @@ -35,8 +34,6 @@ def mack_p(data, average, est_sigma): est_sigma = [("mack", "Mack"), ("log-linear", "log-linear")] - - @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) diff --git a/chainladder/development/tests/rtest_munich.py b/chainladder/development/tests/rtest_munich.py index ee7e2fbd6..77ab7b808 100644 --- a/chainladder/development/tests/rtest_munich.py +++ b/chainladder/development/tests/rtest_munich.py @@ -1,17 +1,17 @@ -### Building out a dev environment with a working copy -### of R ChainLadder is difficult. These tests are -### Currently inactive, but available should the compatibility -### of the installs improve at a later date. +# Building out a dev environment with a working copy +# of R ChainLadder is difficult. These tests are +# Currently inactive, but available should the compatibility +# of the installs improve at a later date. -import numpy as np import chainladder as cl import pytest try: from rpy2.robjects.packages import importr from rpy2.robjects import r + CL = importr("ChainLadder") -except: +except ImportError: pass @@ -34,4 +34,4 @@ def test_mcl_incurred(): ) xp = p.ldf_.get_array_module() arr = xp.array(df[0]) - assert xp.allclose(arr, p.munich_full_triangle_[1, 0, 0, :, :], atol=1e-5) \ No newline at end of file + assert xp.allclose(arr, p.munich_full_triangle_[1, 0, 0, :, :], atol=1e-5) diff --git a/chainladder/methods/tests/rtest_mack.py b/chainladder/methods/tests/rtest_mack.py index 6fa99a6ae..48d390a46 100644 --- a/chainladder/methods/tests/rtest_mack.py +++ b/chainladder/methods/tests/rtest_mack.py @@ -1,17 +1,17 @@ -### Building out a dev environment with a working copy -### of R ChainLadder is difficult. These tests are -### Currently inactive, but available should the compatibility -### of the installs improve at a later date. +# Building out a dev environment with a working copy +# of R ChainLadder is difficult. These tests are +# Currently inactive, but available should the compatibility +# of the installs improve at a later date. -import numpy as np import pytest import chainladder as cl try: from rpy2.robjects.packages import importr from rpy2.robjects import r + CL = importr("ChainLadder") -except: +except ImportError: pass @@ -66,6 +66,7 @@ def test_mack_full_std_err(data, averages, est_sigma, tail, atol): r = xp.array(df[0]) assert xp.allclose(r, p, atol=atol) + @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) @@ -79,6 +80,7 @@ def test_mack_process_risk(data, averages, est_sigma, tail, atol): r = xp.array(df[0]) assert xp.allclose(r, p, atol=atol) + @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) @@ -92,6 +94,7 @@ def test_mack_parameter_risk(data, averages, est_sigma, tail, atol): r = xp.array(df[0]) assert xp.allclose(r, p, atol=atol) + @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) @@ -105,6 +108,7 @@ def test_mack_total_process_risk(data, averages, est_sigma, tail, atol): r = xp.array(df[0])[None, ...] assert xp.allclose(r, xp.nan_to_num(p), atol=atol) + @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) @@ -118,6 +122,7 @@ def test_mack_total_parameter_risk(data, averages, est_sigma, tail, atol): r = xp.array(df[0])[None] assert xp.allclose(r, xp.nan_to_num(p), atol=atol) + @pytest.mark.r @pytest.mark.parametrize("data", data) @pytest.mark.parametrize("averages", averages) @@ -131,6 +136,7 @@ def test_mack_mack_std_err_(data, averages, est_sigma, tail, atol): r = xp.array(df[0]) assert xp.allclose(r, xp.nan_to_num(p), atol=atol) + @pytest.mark.r def test_mack_asymmetric(): r("Paid <- matrix(NA, 45, 45)") @@ -139,5 +145,12 @@ def test_mack_asymmetric(): tri = cl.load_sample("quarterly")["paid"] xp = tri.get_array_module() assert round(float(xp.array(out.rx("Mack.S.E")[0])[-1, -1]), 2) == round( - float(cl.MackChainladder().fit(tri).summary_.to_frame(origin_as_datetime=False).iloc[-1, -1]), 2 - ) \ No newline at end of file + float( + cl + .MackChainladder() + .fit(tri) + .summary_.to_frame(origin_as_datetime=False) + .iloc[-1, -1] + ), + 2, + ) diff --git a/chainladder/tails/tests/rtest_exponential.py b/chainladder/tails/tests/rtest_exponential.py index 6ea6a2926..0217381af 100644 --- a/chainladder/tails/tests/rtest_exponential.py +++ b/chainladder/tails/tests/rtest_exponential.py @@ -1,12 +1,12 @@ -import numpy as np import pytest import chainladder as cl try: from rpy2.robjects.packages import importr from rpy2.robjects import r + CL = importr("ChainLadder") -except: +except ImportError: pass @@ -113,4 +113,4 @@ def test_tail_doesnt_mutate_sigma_(data, averages, est_sigma): p = mack_p(data, averages[0], est_sigma[0]).sigma_ xp = p.get_array_module() p_no_tail = mack_p_no_tail(data, averages[0], est_sigma[0]).sigma_.values - xp.testing.assert_array_equal(p_no_tail, p.values[:, :, :, :-1]) \ No newline at end of file + xp.testing.assert_array_equal(p_no_tail, p.values[:, :, :, :-1]) diff --git a/pyproject.toml b/pyproject.toml index a281732be..1c2a57af4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,13 +113,7 @@ select = ["E2", "E4", "E7", "E9", "F", "B018", "UP034", "N802"] # check can be required without blocking unrelated PRs. Remove entries as # files are cleaned up. [tool.ruff.lint.per-file-ignores] -"chainladder/core/tests/rtest_correlation.py" = ["E266", "E722", "F821"] "chainladder/core/tests/test_display.py" = ["E722"] -"chainladder/development/tests/rtest_clark.py" = ["E266", "E722"] -"chainladder/development/tests/rtest_development.py" = ["E266", "E722", "F401"] -"chainladder/development/tests/rtest_munich.py" = ["E266", "E722", "F401"] -"chainladder/methods/tests/rtest_mack.py" = ["E266", "E722", "F401"] -"chainladder/tails/tests/rtest_exponential.py" = ["E722", "F401"] "docs/friedland/chapter_10.ipynb" = ["E731", "F841"] "docs/friedland/chapter_7_part_2.ipynb" = ["N802"] "docs/friedland/chapter_9.ipynb" = ["E731"]