Skip to content

Commit

Permalink
Fix call to write_summary_levels - missing IL options (OasisLMF#1093)
Browse files Browse the repository at this point in the history
* Fix call to write_summary_levels - missing IL options

* Add IL columns to "GUL" summary section & fix non-oed column detection
  • Loading branch information
sambles authored Sep 8, 2022
1 parent b3a1b03 commit 8857ae5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion oasislmf/computation/generate/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def run(self):

# If exposure summary set, write valid columns for summary levels to file
if summarise_exposure:
write_summary_levels(location_df, self.oed_location_csv, target_dir)
write_summary_levels(location_df, self.oed_accounts_csv, target_dir)

# Write the GUL input files
files_prefixes = self.oasis_files_prefixes
Expand Down
21 changes: 7 additions & 14 deletions oasislmf/preparation/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,31 +257,24 @@ def write_summary_levels(exposure_df, accounts_fp, target_dir):
}

# GUL perspective (loc columns only)
#l_col_list = exposure_df.loc[:, exposure_df.any()].columns.to_list()
# NOTE: work around for pandas==1.2.0, any() not returning return the 'category' field types
l_col_list = exposure_df.replace(0, np.nan).dropna(how='any', axis=1).columns.to_list()

l_col_info = get_loc_dtypes()
for k in list(l_col_info.keys()):
l_col_info[k.lower()] = l_col_info[k]
del l_col_info[k]

l_col_info = {k.lower(): v for k, v in get_loc_dtypes().items()}
gul_avail = {k: l_col_info[k]['desc'] if k in l_col_info else desc_non_oed
for k in set([c.lower() for c in l_col_list]).difference(int_excluded_cols)}
gul_summary_lvl = {'GUL': {'available': {**gul_avail, **int_oasis_cols}}}

# IL perspective (join of acc + loc col with no dups)
il_summary_lvl = {}
il_avail = {}
if accounts_fp:
accounts_df = get_dataframe(accounts_fp, lowercase_cols=False)
accounts_df = get_dataframe(accounts_fp, lowercase_cols=True)
a_col_list = accounts_df.loc[:, ~accounts_df.isnull().all()].columns.to_list()
a_col_info = get_acc_dtypes()
a_col_info = {k.lower(): v for k, v in get_acc_dtypes().items()}
a_avail = set([c.lower() for c in a_col_list])

il_avail = {k: a_col_info[k]['desc'] if k in a_col_info else desc_non_oed
for k in a_avail.difference(gul_avail.keys())}
il_summary_lvl = {'IL': {'available': {**gul_avail, **il_avail, **int_oasis_cols}}}

# Write JSON
gul_summary_lvl = {'GUL': {'available': {**gul_avail, **il_avail, **int_oasis_cols}}}
il_summary_lvl = {'IL': {'available': {**gul_avail, **il_avail, **int_oasis_cols}}} if il_avail else {}
with io.open(os.path.join(target_dir, 'exposure_summary_levels.json'), 'w', encoding='utf-8') as f:
f.write(json.dumps({**gul_summary_lvl, **il_summary_lvl}, sort_keys=True, ensure_ascii=False, indent=4))

Expand Down

0 comments on commit 8857ae5

Please sign in to comment.