Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve I/E handling #260

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3167,11 +3167,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
Loading