chainladder-python icon indicating copy to clipboard operation
chainladder-python copied to clipboard

Store origin label as an attribute

Open genedan opened this issue 2 years ago • 4 comments

Related to #416. I propose we keep the origin label metadata, this way the user can distinguish between different origin bases, such as accident year vs policy year, etc.

cl.load_sample('xyz')
                                       Triangle Summary
Valuation:                                      2008-12
Grain:                                             OYDY
Shape:                                   (1, 5, 11, 11)
Index:                                          [Total]
Origin:                                  [AccidentYear]
Columns:    [Incurred, Paid, Reported, Closed, Premium]

genedan avatar Mar 02 '23 13:03 genedan

I think some unit tests are failing likely because the olab field isn't being passed through in all the transform methods. Without investiagting, it may need to also be added to some of the serializing/deserializing functions like to_json and read_json. I'm not sure, but the unit test failures should implicate gaps.

jbogaardt avatar Mar 02 '23 16:03 jbogaardt

@genedan do you still need the origin label in the metadata? I can help take a look at this.

kennethshsu avatar Sep 25 '23 01:09 kennethshsu

Yeah that would be good. I'm a little bogged down at the moment so I would appreciate it.

genedan avatar Sep 28 '23 03:09 genedan

Just so I understand this request, you basically want to know what built the Triangle object, and be able to get the strings back from the DataFrame right? For example:

import chainladder as cl
import pandas as pd
xyz = cl.load_sample("xyz")

Yields:

cl.load_sample('xyz')
                                       Triangle Summary
Valuation:                                      2008-12
Grain:                                             OYDY
Shape:                                   (1, 5, 11, 11)
Index:                                          [Total]
Origin:                                  [AccidentYear]
Columns:    [Incurred, Paid, Reported, Closed, Premium]

And you need something that'll do this?

print("columns_label:", xyz.columns_label)
print("index_label:", xyz.index_label)
print("origin_label:", xyz.origin_label)

Returns:

columns_label: ['Incurred', 'Paid', 'Reported', 'Closed', 'Premium']
index_label: ['Total']
origin_label: ['AccidentYear']

kennethshsu avatar Dec 14 '23 02:12 kennethshsu

You should now be able to do all of the following:

import chainladder as cl
xyz = cl.load_sample("xyz")
print("valuation_date:", xyz.valuation_date)
print("origin_grain:", xyz.origin_grain)
print("development_grain:", xyz.development_grain)
print("xyz.shape:", xyz.shape)
print("index_label:", xyz.index_label)
print("columns_label:", xyz.columns_label)
print("origin_label:", xyz.origin_label)

Everything in the Triangle summary is now visiable as attributes.

kennethshsu avatar Apr 05 '24 02:04 kennethshsu