Skip to content

Commit 060c7d6

Browse files
committed
MetaDataStore drops database when it's deleted from the project
1 parent eeb1685 commit 060c7d6

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

activity_browser/bwutils/metadata.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(self):
5252
self.databases = set()
5353

5454
bd.projects.current_changed.connect(self.reset_metadata)
55+
bd.databases.metadata_changed.connect(self.check_databases)
5556

5657
def add_metadata(self, db_names_list: list) -> None:
5758
"""Include data from the brightway databases.
@@ -172,6 +173,11 @@ def reset_metadata(self) -> None:
172173
self.dataframe = pd.DataFrame()
173174
self.databases = set()
174175

176+
def check_databases(self):
177+
removed_dbs = [db for db in self.databases if db not in bd.databases]
178+
for db in removed_dbs:
179+
self.dataframe.drop(self.dataframe[self.dataframe.database == db].index, inplace=True)
180+
175181
def get_existing_fields(self, field_list: list) -> list:
176182
"""Return a list of fieldnames that exist in the current dataframe."""
177183
return [fn for fn in field_list if fn in self.dataframe.columns]

0 commit comments

Comments
 (0)