diff --git a/chainladder/core/io.py b/chainladder/core/io.py index 127c1f77..b72f0d1b 100644 --- a/chainladder/core/io.py +++ b/chainladder/core/io.py @@ -1,11 +1,14 @@ +""" +Support Triangle I/O capabilities. +""" # 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 pandas as pd + from sklearn.base import BaseEstimator -import json -import joblib -import dill class TriangleIO: diff --git a/chainladder/utils/tests/test_utilities.py b/chainladder/utils/tests/test_utilities.py index c296507e..9c4615b2 100644 --- a/chainladder/utils/tests/test_utilities.py +++ b/chainladder/utils/tests/test_utilities.py @@ -420,6 +420,42 @@ def test_read_pickle_triangle(raa: Triangle, tmp_path: Path) -> None: assert cl.read_pickle(str(pkl_path)) == raa +def test_triangle_to_pickle( + raa: Triangle, + clrd: Triangle, + tmp_path: Path +) -> None: + """ + Dump a pickle of a triangle and read it back in. The read-in triangle should + equal the one that was dumped. + + Parameters + ---------- + raa: Triangle + The raa sample data set Triangle. + clrd: Triangle + The clrd sample data set Triangle. + tmp_path: Path + The builtin pytest tmp_path fixture, provides a temporary path to dump the pickle to. + + Returns + ------- + None + + """ + # Single-dimension case. + 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 + + # 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 + + def test_read_pickle_estimator(raa: Triangle, tmp_path: Path) -> None: """ Create an estimator, dump a pickle of it, and then read it back in. The ingested pickle should result