Skip to content
Open
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
16 changes: 11 additions & 5 deletions chainladder/core/tests/rtest_correlation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand Down
15 changes: 10 additions & 5 deletions chainladder/development/tests/rtest_clark.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)")
Expand All @@ -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")')
Expand Down
13 changes: 5 additions & 8 deletions chainladder/development/tests/rtest_development.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,7 +11,7 @@
from rpy2.robjects import r

CL = importr("ChainLadder")
except:
except ImportError:
pass


Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions chainladder/development/tests/rtest_munich.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
assert xp.allclose(arr, p.munich_full_triangle_[1, 0, 0, :, :], atol=1e-5)

@henrydingliu henrydingliu Sep 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ldf_ is always np. sp.allclose also doesn't exist.

29 changes: 21 additions & 8 deletions chainladder/methods/tests/rtest_mack.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)")
Expand All @@ -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
)
float(
cl
.MackChainladder()
.fit(tri)
.summary_.to_frame(origin_as_datetime=False)
.iloc[-1, -1]
),
2,
)
6 changes: 3 additions & 3 deletions chainladder/tails/tests/rtest_exponential.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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])
xp.testing.assert_array_equal(p_no_tail, p.values[:, :, :, :-1])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ldf_ is always np. sp.testing.assert_array_equal also doesn't exist.

6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading