From d3736f29b1c10d1c774f193c5574ec21f487333a Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Fri, 20 Dec 2024 17:00:43 -0500 Subject: [PATCH 1/3] Add a switch to control I/E override by syssettings --- xl2times/datatypes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xl2times/datatypes.py b/xl2times/datatypes.py index 9c9aa89..8f8a181 100644 --- a/xl2times/datatypes.py +++ b/xl2times/datatypes.py @@ -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, From a4147cd88a0e9f52249d4f90c6092391539e0fd4 Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Fri, 20 Dec 2024 18:50:31 -0500 Subject: [PATCH 2/3] Remove syssettings generated i/e entries --- xl2times/transforms.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xl2times/transforms.py b/xl2times/transforms.py index 6f1aaef..43b741d 100644 --- a/xl2times/transforms.py +++ b/xl2times/transforms.py @@ -3167,11 +3167,31 @@ 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: + # 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 From ecc92741e2735e918eb4f4a124478787b8d083c7 Mon Sep 17 00:00:00 2001 From: Olexandr Balyk Date: Sat, 21 Dec 2024 06:28:19 -0500 Subject: [PATCH 3/3] Reset index --- xl2times/transforms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xl2times/transforms.py b/xl2times/transforms.py index 43b741d..50f89f4 100644 --- a/xl2times/transforms.py +++ b/xl2times/transforms.py @@ -3176,6 +3176,7 @@ def apply_final_fixup( # 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"])