diff --git a/unfold/data_cleaning.py b/unfold/data_cleaning.py index dcaf62c..c207dc8 100644 --- a/unfold/data_cleaning.py +++ b/unfold/data_cleaning.py @@ -409,12 +409,14 @@ def check_commonality_between_databases(original_db, scenario_db, db_name): f"and {db_name}." ) + def change_db_name(data, name): """ Originally from `wurst.linking` module. Change the database of all datasets in ``data`` to ``name``. - Raises errors if each dataset does not have exactly one reference production exchange.""" + Raises errors if each dataset does not have exactly one reference production exchange. + """ get_input_databases = lambda data: {ds.get("database") for ds in data} old_names = get_input_databases(data) @@ -423,4 +425,4 @@ def change_db_name(data, name): for exc in ds["exchanges"]: if exc.get("input") and exc["input"][0] in old_names: exc["input"] = (name, exc["input"][1]) - return data \ No newline at end of file + return data diff --git a/unfold/unfold.py b/unfold/unfold.py index 4b19d5f..819f8c2 100644 --- a/unfold/unfold.py +++ b/unfold/unfold.py @@ -21,15 +21,12 @@ from prettytable import PrettyTable from scipy import sparse as nsp from wurst import extract_brightway2_databases -from wurst.linking import ( - check_duplicate_codes, - check_internal_linking, - link_internal, -) +from wurst.linking import check_duplicate_codes, check_internal_linking, link_internal from .data_cleaning import ( add_biosphere_links, add_product_field_to_exchanges, + change_db_name, check_exchanges_input, check_for_duplicates, correct_fields_format, @@ -37,7 +34,6 @@ get_outdated_units, remove_categories_for_technosphere_flows, remove_missing_fields, - change_db_name ) try: @@ -376,11 +372,19 @@ def generate_factors(self) -> None: """ self.factors = ( - self.scenario_df[[ - c for c in self.scenario_df.columns if c not in [ - "to database", + self.scenario_df[ + [ + c + for c in self.scenario_df.columns + if c + not in [ + "to database", + ] ] - ]].groupby("flow id").sum(numeric_only=True).to_dict("index") + ] + .groupby("flow id") + .sum(numeric_only=True) + .to_dict("index") ) def store_datasets_metadata(self) -> None: