Skip to content

Commit

Permalink
resolves #210
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt committed Sep 18, 2021
1 parent 874ba12 commit ce67e1d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion chainladder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def auto_sparse(auto_sparse=True):
from chainladder.methods import * # noqa (API Import)
from chainladder.workflow import * # noqa (API Import)

__version__ = "0.8.8"
__version__ = "0.8.9"
14 changes: 10 additions & 4 deletions chainladder/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,19 @@ def _to_datetime(data, fields, period_end=False, format=None):
def _development_lag(origin, development):
""" For tabular format, this will convert the origin/development
difference to a development lag """
return ((development - origin) /
return ((development - origin) /
np.timedelta64(1, 'M')).round(0).astype(int)

@staticmethod
def _get_grain(array):
return {1: "Y", 2: "S", 4: "Q"}.get(
len(set(pd.Series(array.unique()).dt.month)), "M")
u = pd.Series(array).dt.month.sort_values().diff().dropna().unique()
u = u[u>0]
if len(u) > 1:
return 'M'
elif len(u) == 0:
return 'Y'
else:
return {6: "2Q", 3: "Q"}.get(u[0], "M")

@staticmethod
def _cartesian_product(*arrays):
Expand Down
1 change: 1 addition & 0 deletions chainladder/core/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def aggregate(i, obj, axis, v):
odims = self.obj._to_datetime(
pd.Series(self.groups.indices.keys()).to_frame(), [0])
obj.origin_grain = self.obj._get_grain(odims)
obj.origin_grain = 'S' if obj.origin_grain == '2Q' else obj.origin_grain
obj.odims = odims.values
obj._set_slicers()
if auto_sparse:
Expand Down
9 changes: 9 additions & 0 deletions chainladder/core/tests/test_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,12 @@ def test_inplace(raa):
t.dev_to_val(inplace=True)
t.val_to_dev(inplace=True)
t.grain('OYDY', inplace=True)

def test_malformed_init():
assert cl.Triangle(
data=pd.DataFrame({
'Accident Date': ['2020-07-23', '2019-07-23', '2018-07-23', '2016-07-23', '2020-08-23', '2019-09-23', '2018-10-23'],
'Valuation Date': ['2021-01-01', '2021-01-01', '2021-01-01', '2021-01-01', '2021-01-01', '2021-01-01', '2021-01-01'],
'Loss': [10000, 10000, 10000, 10000, 0, 0, 0]}),
origin='Accident Date', development='Valuation Date', columns='Loss'
).origin_grain == 'M'
1 change: 1 addition & 0 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(self, data=None, origin=None, development=None, columns=None,
origin_date = self._to_datetime(
data, origin, format=origin_format).rename('__origin__')
self.origin_grain = self._get_grain(origin_date)
self.origin_grain = 'S' if self.origin_grain == '2Q' else self.origin_grain
development_date = self._set_development(
data, development, development_format, origin_date)
self.development_grain = (
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
descr = "Chainladder Package - P&C Loss Reserving package "
name = 'chainladder'
url = '/~https://github.com/casact/chainladder-python'
version='0.8.8' # Put this in __init__.py
version='0.8.9' # Put this in __init__.py

data_path = ''
setup(
Expand Down

0 comments on commit ce67e1d

Please sign in to comment.