Skip to content

Commit

Permalink
Improve I/E handling (#260)
Browse files Browse the repository at this point in the history
Closes #258
  • Loading branch information
olejandro authored Dec 23, 2024
1 parent 8a46fda commit 598d19d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xl2times/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ class Config:
# Names of regions to include in the model; if empty, all regions are included.
filter_regions: set[str]
times_sets: dict[str, list[str]]
# Switch to prevent overwriting of I/E settings in BASE and SubRES
ie_override_in_syssettings: bool = False

def __init__(
self,
Expand Down
21 changes: 21 additions & 0 deletions xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3169,11 +3169,32 @@ def apply_final_fixup(
"sow",
"stage",
"module_name",
"module_type",
}
df.dropna(subset="value", inplace=True)
drop_cols = [col for col in df.columns if col != "value" and col not in keep_cols]
df.drop(columns=drop_cols, inplace=True)
df = df.drop_duplicates(subset=list(keep_cols), keep="last")

# Control application of i/e rules from syssettings
if not config.ie_override_in_syssettings:
df = df.reset_index(drop=True)
# Remove i/e rules from syssettings if present in BASE and SubRES
i = (df["year"] == 0) & (
df["module_type"].isin(["base", "syssettings", "subres"])
)
duplicated = df[i].duplicated(
subset=[
col
for col in keep_cols
if col != "value" and col not in {"module_name", "module_type"}
],
keep=False,
)
i = (df["module_type"] == "syssettings") & duplicated
if any(i):
df = df[~i]

tables[Tag.fi_t] = df.reset_index(drop=True)

return tables
Expand Down

0 comments on commit 598d19d

Please sign in to comment.