Skip to content

Commit

Permalink
simplify load sample utility
Browse files Browse the repository at this point in the history
  • Loading branch information
genedan committed Nov 14, 2022
1 parent 9749110 commit 4f21439
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions faslr/utilities/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@
from chainladder import Triangle


def load_sample(sample_name: str) -> Triangle:
samples = {
'mack97': 'mack_1997.csv',
'us_industry_auto': 'friedland_us_industry_auto.csv',
'uspp_incr_case': 'friedland_uspp_auto_increasing_case.csv',
'xyz': 'friedland_xyz_auto_bi.csv',
'us_auto_steady_state': 'friedland_us_auto_steady_state.csv'
}


def load_sample(
sample_name: str
) -> Triangle:

path = os.path.dirname(os.path.abspath(__file__))
if sample_name == "mack97":
df_csv = pd.read_csv(
os.path.join(path, "..", "samples", "mack_1997.csv"))
elif sample_name == "us_industry_auto":
df_csv = pd.read_csv(
os.path.join(path, "..", "samples", "friedland_us_industry_auto.csv"))
elif sample_name == "uspp_incr_case":
df_csv = pd.read_csv(
os.path.join(path, "..", "samples", "friedland_uspp_auto_increasing_case.csv"))
elif sample_name == "xyz":

def join_path(
fname: str
):

joined = os.path.join(path, "..", "samples", fname)
return joined

try:
df_csv = pd.read_csv(
os.path.join(path, "..", "samples", "friedland_xyz_auto_bi.csv"))
else:
join_path(samples[sample_name])
)
except KeyError:
raise Exception("Invalid sample name.")

if sample_name != "mack97":
Expand Down

0 comments on commit 4f21439

Please sign in to comment.