Skip to content

Commit

Permalink
Download only required misc tables
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Aug 15, 2024
1 parent b760c8d commit 264884d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions audb/core/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,15 @@ def _load_files(
def _misc_tables_used_in_scheme(
db: audformat.Database,
) -> typing.List[str]:
r"""List of misc tables that are used inside a scheme."""
r"""List of misc tables that are used inside a scheme.
Args:
db: database object
Returns:
unique list of misc tables used in schemes
"""
misc_tables_used_in_scheme = []
for scheme in db.schemes.values():
if scheme.uses_table:
Expand Down Expand Up @@ -1747,14 +1755,23 @@ def load_table(
version,
)

# Find misc tables used in schemes of the requested table
scheme_misc_tables = []
for column_id, column in db[table].columns.items():
if column.scheme_id is not None:
scheme = db.schemes[column.scheme_id]
if scheme.uses_table:
scheme_misc_tables.append(scheme.labels)
scheme_misc_tables = audeer.unique(scheme_misc_tables)

# Load table
tables = _misc_tables_used_in_scheme(db) + [table]
tables = scheme_misc_tables + [table]
for _table in tables:
table_file = os.path.join(db_root, f"db.{_table}")
if not (
os.path.exists(f"{table_file}.csv")
or os.path.exists(f"{table_file}.pkl")
):
# `_load_files()` downloads a table
# from the backend,
# if it cannot find its corresponding csv or parquet file
if not os.path.exists(f"{table_file}.pkl"):
_load_files(
[_table],
"table",
Expand Down

0 comments on commit 264884d

Please sign in to comment.