From 88c52fb3ca87fa333cf7d7ece5e6aa5fccf8d67c Mon Sep 17 00:00:00 2001 From: Adam Hoelscher Date: Sun, 11 May 2025 06:43:43 +0000 Subject: [PATCH 1/5] pass tests with new chainladder --- pyproject.toml | 5 ++--- src/tryangle/ensemble/base.py | 2 +- src/tryangle/metrics/score.py | 11 +++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4d12bb9..3adbeec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ "Topic :: Office/Business :: Financial", "Topic :: Scientific/Engineering :: Artificial Intelligence", ] -dependencies = ["chainladder<=0.8.14", "pandas<2.0", "scikit-learn>=1.2"] +dependencies = ["chainladder>=0.8.24"] license = { text = "MPL-2.0" } requires-python = ">=3.11" @@ -25,5 +25,4 @@ requires-python = ">=3.11" Homepage = "https://github.com/casact/tryangle" [project.optional-dependencies] -dev = ["ruff", "black", "mypy", "pytest", "tox", "twine"] - +dev = ["ruff", "black", "mypy", "pytest", "tox", "twine"] \ No newline at end of file diff --git a/src/tryangle/ensemble/base.py b/src/tryangle/ensemble/base.py index 36c2e4f..1a2762e 100644 --- a/src/tryangle/ensemble/base.py +++ b/src/tryangle/ensemble/base.py @@ -186,7 +186,7 @@ def preprocess(self, X, y=None, sample_weight=None): clone(clf), X, X, - sample_weight=None, + fit_params={}, message_clsname=f"Preprocessing - {names[idx]}_expected", message=self._log_message(names[idx], idx + 1, len(clfs)), ), diff --git a/src/tryangle/metrics/score.py b/src/tryangle/metrics/score.py index 8d3c7b7..e66ba67 100644 --- a/src/tryangle/metrics/score.py +++ b/src/tryangle/metrics/score.py @@ -3,12 +3,11 @@ # file, You can obtain one at https://mozilla.org/MPL/2.0/. import numpy as np +from sklearn.metrics import mean_squared_error +from sklearn.metrics._scorer import _BaseScorer from tryangle.metrics.base import get_actual_expected -from sklearn.metrics._scorer import _BaseScorer -from sklearn.metrics import mean_squared_error - class AVEScore(_BaseScorer): """Base AvE scoring class""" @@ -17,9 +16,13 @@ def __init__( self, score_func=mean_squared_error, sign=-1, - kwargs={"squared": False}, + kwargs=None, weighted=False, ): + + if kwargs is None: + kwargs = {} + self.weighted = weighted super().__init__(score_func, sign, kwargs) From 660978b9857a95a8e9719eb31f09cd7ceb705baf Mon Sep 17 00:00:00 2001 From: Adam Hoelscher Date: Sun, 11 May 2025 06:45:29 +0000 Subject: [PATCH 2/5] deal with distutil dep --- tests/test_ensemble.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_ensemble.py b/tests/test_ensemble.py index a65d8dd..587e2dc 100644 --- a/tests/test_ensemble.py +++ b/tests/test_ensemble.py @@ -3,11 +3,12 @@ # file, You can obtain one at https://mozilla.org/MPL/2.0/. import os -from distutils import dir_util +import shutil import numpy as np import pytest from chainladder.utils import load_sample + from tryangle.core.base import TryangleData from tryangle.core.methods import BornhuetterFerguson, CapeCod, Chainladder from tryangle.ensemble.base import AutoEnsemble @@ -46,7 +47,7 @@ def data_dir(tmpdir, request): test_dir, _ = os.path.splitext(filename) if os.path.isdir(test_dir): - dir_util.copy_tree(test_dir, str(tmpdir)) + shutil.copytree(test_dir, str(tmpdir), dirs_exist_ok=True) return tmpdir From 23f46a87fff86dcb87484d8e37767c147a0f345a Mon Sep 17 00:00:00 2001 From: Adam Hoelscher Date: Sun, 11 May 2025 06:45:56 +0000 Subject: [PATCH 3/5] run black --- docs/conf.py | 23 ++++++++++++----------- examples/plot_auto_ensemble.py | 1 + examples/plot_gridsearch_pipeline.py | 1 + src/tryangle/utils/datasets.py | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4fc48e9..d7d3be4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,16 +12,17 @@ # import os import sys -sys.path.insert(0, os.path.abspath('../src')) + +sys.path.insert(0, os.path.abspath("../src")) print(sys.path[0]) sys.setrecursionlimit(1500) # -- Project information ----------------------------------------------------- -project = 'tryangle' -copyright = '2021, Caesar Balona & Ronald Richman' -author = 'Caesar Balona & Ronald Richman' +project = "tryangle" +copyright = "2021, Caesar Balona & Ronald Richman" +author = "Caesar Balona & Ronald Richman" # -- General configuration --------------------------------------------------- @@ -30,19 +31,19 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.napoleon', - 'sphinx.ext.autosummary', + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", + "sphinx.ext.autosummary", ] autosummary_generate = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- @@ -50,9 +51,9 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "alabaster" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] diff --git a/examples/plot_auto_ensemble.py b/examples/plot_auto_ensemble.py index 9c38f04..3906bcf 100644 --- a/examples/plot_auto_ensemble.py +++ b/examples/plot_auto_ensemble.py @@ -6,6 +6,7 @@ Finds optimal weights to combine chainladder and bornhuetter ferguson methods to reduce prediction error. """ + from tryangle.model_selection import TriangleSplit from tryangle.utils.datasets import load_sample from tryangle.ensemble import AutoEnsemble, Adam diff --git a/examples/plot_gridsearch_pipeline.py b/examples/plot_gridsearch_pipeline.py index 241e336..1bcd37d 100644 --- a/examples/plot_gridsearch_pipeline.py +++ b/examples/plot_gridsearch_pipeline.py @@ -9,6 +9,7 @@ Since selecting development factors is a transformation, it can be pipelined with an estimator """ + from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline from tryangle import Development, CapeCod diff --git a/src/tryangle/utils/datasets.py b/src/tryangle/utils/datasets.py index f7b8ffc..ce47c91 100644 --- a/src/tryangle/utils/datasets.py +++ b/src/tryangle/utils/datasets.py @@ -36,7 +36,7 @@ def load_sample(key, *args, **kwargs): columns=columns, cumulative=True, *args, - **kwargs + **kwargs, ) sample_weight = Triangle( sample_weight, @@ -46,7 +46,7 @@ def load_sample(key, *args, **kwargs): columns=["premium"], cumulative=True, *args, - **kwargs + **kwargs, ).latest_diagonal return TryangleData(claim, sample_weight) @@ -73,7 +73,7 @@ def load_test_sample(key, *args, **kwargs): columns=["claim"], cumulative=True, *args, - **kwargs + **kwargs, ) if key.lower() in ["swiss"]: From f65087c093c2cc114ecb493b34cce05cdd47cb1f Mon Sep 17 00:00:00 2001 From: Adam Hoelscher Date: Tue, 13 May 2025 04:02:50 +0000 Subject: [PATCH 4/5] update env --- pyproject.toml | 6 ++++-- tox.ini | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3adbeec..5ec2a6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,9 +17,11 @@ classifiers = [ "Topic :: Office/Business :: Financial", "Topic :: Scientific/Engineering :: Artificial Intelligence", ] -dependencies = ["chainladder>=0.8.24"] +dependencies = [ + "chainladder>=0.8.24" +] license = { text = "MPL-2.0" } -requires-python = ">=3.11" +requires-python = ">=3.9" [project.urls] Homepage = "https://github.com/casact/tryangle" diff --git a/tox.ini b/tox.ini index d628ecc..59e4a6f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,10 @@ [tox] -envlist = {py3.9.17, py3.10.12, py3.11.4}-chainladder{0.8.14} +envlist = py3.{9-12}-chainladder{0.8.24} [testenv] # install pytest in the virtualenv where commands will be executed deps = pytest - chainladder0.8.14: chainladder==0.8.14 commands = # NOTE: you can run any command line tool here - not just tests pytest \ No newline at end of file From 81dea240309d7481ccecd13704be906a8f554148 Mon Sep 17 00:00:00 2001 From: Adam Hoelscher Date: Tue, 13 May 2025 19:35:32 +0000 Subject: [PATCH 5/5] expand tox.ini --- pyproject.toml | 4 ++-- tox.ini | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5ec2a6e..a9d09ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ "Topic :: Scientific/Engineering :: Artificial Intelligence", ] dependencies = [ - "chainladder>=0.8.24" + "chainladder>=0.8,<=0.8.24" ] license = { text = "MPL-2.0" } requires-python = ">=3.9" @@ -27,4 +27,4 @@ requires-python = ">=3.9" Homepage = "https://github.com/casact/tryangle" [project.optional-dependencies] -dev = ["ruff", "black", "mypy", "pytest", "tox", "twine"] \ No newline at end of file +dev = ["ruff", "black", "mypy", "pytest", "tox", "twine", "tox-uv"] \ No newline at end of file diff --git a/tox.ini b/tox.ini index 59e4a6f..6408c49 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,41 @@ [tox] -envlist = py3.{9-12}-chainladder{0.8.24} +envlist = py3.{9-13}-chainladder0.8.{24, 23, 22, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} [testenv] # install pytest in the virtualenv where commands will be executed deps = pytest + sparse<0.16 commands = # NOTE: you can run any command line tool here - not just tests - pytest \ No newline at end of file + pytest {posargs:tests} + +[testenv:chainladder] +description = run tests with multiple versions +deps = + 0.8.24: chainladder==0.8.24 + 0.8.23: chainladder==0.8.23 + 0.8.22: chainladder==0.8.22 + 0.8.20: chainladder==0.8.20 + 0.8.19: chainladder==0.8.19 + 0.8.18: chainladder==0.8.18 + 0.8.17: chainladder==0.8.17 + 0.8.16: chainladder==0.8.16 + 0.8.15: chainladder==0.8.15 + 0.8.14: chainladder==0.8.14 + 0.8.13: chainladder==0.8.13 + 0.8.12: chainladder==0.8.12 + 0.8.11: chainladder==0.8.11 + 0.8.10: chainladder==0.8.10 + 0.8.9: chainladder==0.8.9 + 0.8.8: chainladder==0.8.8 + 0.8.7: chainladder==0.8.7 + 0.8.6: chainladder==0.8.6 + 0.8.5: chainladder==0.8.5 + 0.8.4: chainladder==0.8.4 + 0.8.3: chainladder==0.8.3 + 0.8.2: chainladder==0.8.2 + 0.8.1: chainladder==0.8.1 + 0.8.0: chainladder==0.8.0 +commands = + pytest {posargs:tests} \ No newline at end of file