Skip to content

Commit

Permalink
Don't assume delete section present
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Sep 25, 2024
1 parent 9891ed0 commit 34f7612
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ecoinvent_migrate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def generate_biosphere_mapping(
keep_deletions=keep_deletions,
)
affected_uuids = {
o["source"]["uuid"] for o in itertools.chain(data["replace"], data["delete"])
o["source"]["uuid"]
for o in itertools.chain(data.get("replace", []), data.get("delete", []))
}
data = supplement_biosphere_changes_with_real_data_comparison(
data=data,
Expand All @@ -271,9 +272,7 @@ def generate_biosphere_mapping(
)

if not data["delete"] and not data["replace"]:
logger.info(
"It seems like there are no biosphere changes for this release. Doing nothing."
)
logger.info("It seems like there are no biosphere changes for this release. Doing nothing.")
return

dp = Datapackage(
Expand Down Expand Up @@ -355,6 +354,8 @@ def format(ecospold: dict) -> dict:
# Patch changes which aren't included in the change report
for key_source, value_source in source_ee.items():
if key_source not in target_ee and key_source not in affected_uuids:
if "delete" not in data:
data["delete"] = []
data["delete"].append(
{
"source": {"uuid": key_source, "name": value_source["name"]},
Expand Down
4 changes: 3 additions & 1 deletion ecoinvent_migrate/wrangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ def source_target_biosphere_pair(
for obj in lst:
if "comment" in obj and (not obj["comment"] or isnan(obj["comment"])):
del obj["comment"]
if "conversion_factor" in obj and (obj["conversion_factor"] == 1.0 or isnan(obj["conversion_factor"])):
if "conversion_factor" in obj and (
obj["conversion_factor"] == 1.0 or isnan(obj["conversion_factor"])
):
del obj["conversion_factor"]

return formatted

0 comments on commit 34f7612

Please sign in to comment.