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

Support processing of val_cond #249

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all 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
7 changes: 6 additions & 1 deletion xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,7 @@ def query(
attribute: str | None,
region: str | None,
year: int | None,
val: int | float | None,
) -> pd.Index:
qs = []

Expand Down Expand Up @@ -2419,6 +2420,8 @@ def query(
qs.append(f"region == '{region}'")
if year not in [None, ""]:
qs.append(f"year == {year}")
if val not in [None, ""]:
qs.append(f"value == {val}")
query_str = " and ".join(qs)
row_idx = table.query(query_str).index
return row_idx
Expand Down Expand Up @@ -2464,6 +2467,7 @@ def apply_transform_tables(
row["attribute"],
row["region"],
row["year"],
row["val_cond"],
)

if not any(rows_to_update):
Expand Down Expand Up @@ -2507,7 +2511,7 @@ def apply_transform_tables(

# Query for rows with matching process/commodity and region
rows_to_update = query(
table, row["process"], row["commodity"], None, row["region"], None
table, row["process"], row["commodity"], None, row["region"], None, None
)
# Overwrite (inplace) the column given by the attribute (translated by attr_prop)
# with the value from row
Expand Down Expand Up @@ -2537,6 +2541,7 @@ def apply_transform_tables(
row["attribute"],
row["region"],
row["year"],
row["val_cond"],
)

if not any(rows_to_update):
Expand Down