diff --git a/src/graphnet/data/utilities/sqlite_utilities.py b/src/graphnet/data/utilities/sqlite_utilities.py index cfa308ba2..8764bae3c 100644 --- a/src/graphnet/data/utilities/sqlite_utilities.py +++ b/src/graphnet/data/utilities/sqlite_utilities.py @@ -46,6 +46,8 @@ def get_primary_keys(database: str) -> Tuple[Dict[str, str], str]: query = 'SELECT name FROM sqlite_master WHERE type == "table"' table_names = [table[0] for table in conn.execute(query).fetchall()] + assert len(table_names) > 0, "No tables found in database." + integer_primary_key = {} for table in table_names: query = f"SELECT l.name FROM pragma_table_info('{table}') as l WHERE l.pk = 1;" diff --git a/src/graphnet/data/writers/sqlite_writer.py b/src/graphnet/data/writers/sqlite_writer.py index ab8d95051..ab4b32094 100644 --- a/src/graphnet/data/writers/sqlite_writer.py +++ b/src/graphnet/data/writers/sqlite_writer.py @@ -160,7 +160,14 @@ def _merge_databases( for file_count, input_file in tqdm(enumerate(files), colour="green"): # Extract table names and index column name in database - tables, primary_key = get_primary_keys(database=input_file) + try: + tables, primary_key = get_primary_keys(database=input_file) + except AssertionError as e: + if "No tables found in database." in str(e): + self.warning(f"Database {input_file} is empty. Skipping.") + continue + else: + raise e for table_name in tables.keys(): # Extract all data in the table from the given database