Skip to content

Commit

Permalink
resolves #69 Problems converting a triangle to a higher grain using t…
Browse files Browse the repository at this point in the history
…he grain method
  • Loading branch information
John Bogaardt committed Mar 17, 2020
1 parent 7a0ea9c commit f11e588
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions chainladder/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,23 @@ def _to_datetime(data, fields, period_end=False, format=None):
else:
target_field = data[fields].iloc[:, 0]
if hasattr(target_field, 'dt'):
return target_field
datetime_arg = target_field.unique()
date_inference_list = \
[{'arg': datetime_arg, 'format': '%Y%m'},
{'arg': datetime_arg, 'format': '%Y'},
{'arg': datetime_arg, 'infer_datetime_format': True}]
if format is not None:
date_inference_list = [{'arg': datetime_arg, 'format': format}] + \
date_inference_list
for item in date_inference_list:
try:
arr = dict(zip(datetime_arg, pd.to_datetime(**item)))
break
except:
pass
target = target_field.map(arr)
target = target_field
else:
datetime_arg = target_field.unique()
date_inference_list = \
[{'arg': datetime_arg, 'format': '%Y%m'},
{'arg': datetime_arg, 'format': '%Y'},
{'arg': datetime_arg, 'infer_datetime_format': True}]
if format is not None:
date_inference_list = [{'arg': datetime_arg, 'format': format}] + \
date_inference_list
for item in date_inference_list:
try:
arr = dict(zip(datetime_arg, pd.to_datetime(**item)))
break
except:
pass
target = target_field.map(arr)
if period_end:
target = target.dt.to_period(
TriangleBase._get_grain(target)
Expand Down

0 comments on commit f11e588

Please sign in to comment.