Skip to content

Commit

Permalink
Updates to the functions get_relevant_flows and get_relevant_activiti…
Browse files Browse the repository at this point in the history
…es (#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.
  • Loading branch information
Zoophobus authored Oct 14, 2023
1 parent 400cc35 commit 0916c44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions activity_browser/bwutils/superstructure/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion activity_browser/bwutils/superstructure/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0916c44

Please sign in to comment.