From 0916c449fa3f5c35b52be1037213f2bd0dacb3c1 Mon Sep 17 00:00:00 2001 From: Jonathan Kidner <12627199+Zoophobus@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:04:36 +0200 Subject: [PATCH] Updates to the functions get_relevant_flows and get_relevant_activities (#1069) * Updates to the functions from de Koning (get_relevant_flows and get_relevant_activities), avoiding use of pandas apply and using python map functionality for splitting pandas dataframes. * Update the use of DataFrame.applymap to DataFrame.map in the excel file importer module. --- activity_browser/bwutils/superstructure/activities.py | 6 ++++-- activity_browser/bwutils/superstructure/excel.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/activity_browser/bwutils/superstructure/activities.py b/activity_browser/bwutils/superstructure/activities.py index 97c990012..ead625063 100644 --- a/activity_browser/bwutils/superstructure/activities.py +++ b/activity_browser/bwutils/superstructure/activities.py @@ -91,7 +91,8 @@ def get_relevant_activities(df: pd.DataFrame, part: str = "from") -> dict: if sub.empty: return {} - names, products, locations, dbs = sub.iloc[:, 0:4].apply(set, axis=0) + names, products, locations, dbs = list(map(set, sub.iloc[:, 0:4].values.T)) +# names, products, locations, dbs = sub.iloc[:, 0:4].apply(set, axis=0) query = (ActivityDataset .select(ActivityDataset.name, ActivityDataset.product, ActivityDataset.location, ActivityDataset.database, @@ -113,7 +114,8 @@ def get_relevant_flows(df: pd.DataFrame, part: str = "from") -> dict: if sub.empty: return {} - names, categories, dbs = sub.iloc[:, 0:3].apply(set, axis=0) + names, categories, dbs = list(map(set, sub.iloc[:, 0:3].values.T)) +# names, categories, dbs = sub.iloc[:, 0:3].apply(set, axis=0) query = (ActivityDataset .select(ActivityDataset.name, ActivityDataset.data, ActivityDataset.database, ActivityDataset.code) diff --git a/activity_browser/bwutils/superstructure/excel.py b/activity_browser/bwutils/superstructure/excel.py index 9d6435c24..e009c624f 100644 --- a/activity_browser/bwutils/superstructure/excel.py +++ b/activity_browser/bwutils/superstructure/excel.py @@ -83,7 +83,7 @@ def import_from_excel(document_path: Union[str, Path], import_sheet: int = 1) -> # Convert specific columns that may have tuples as strings columns = ["from categories", "from key", "to categories", "to key"] - data.loc[:, columns] = data[columns].applymap(convert_tuple_str) + data.loc[:, columns] = data[columns].map(convert_tuple_str) except: # skip the error checks here, these now occur in the calling layout.tabs.LCA_setup module pass