Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repositories argument to audb.available() #489

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion audb/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
def available(
*,
only_latest: bool = False,
repositories: Repository | Sequence[Repository] = None,
ChristianGeng marked this conversation as resolved.
Show resolved Hide resolved
) -> pd.DataFrame:
r"""List all databases that are available to the user.

Args:
only_latest: include only latest version of database
repositories: search only in the given repositories
ChristianGeng marked this conversation as resolved.
Show resolved Hide resolved

Returns:
table with database name as index,
Expand Down Expand Up @@ -59,7 +61,12 @@ def add_database(name: str, version: str, repository: Repository):
]
)

for repository in config.REPOSITORIES:
if repositories is not None:
repositories = audeer.to_list(repositories)
else:
repositories = config.REPOSITORIES
sourcery-ai[bot] marked this conversation as resolved.
Show resolved Hide resolved

for repository in repositories:
try:
backend_interface = repository.create_backend_interface()
with backend_interface.backend as backend:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ def test_default(self):
assert "name0" in df.index
assert "name1" in df.index

def test_repositories_all(self):
"""Test repositories argument with all repositories."""
df = audb.available(repositories=audb.config.REPOSITORIES)
assert len(df) == 2

hagenw marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("repository_index", [0, 1])
@pytest.mark.parametrize("as_list", [False, True])
def test_repositories_single(self, repository_index, as_list):
"""Test repositories argument with single repositories.

Args:
repository_index: select single repository
by the given index
from ``audb.config.REPOSITORIES``
as_list: if ``True``,
single repository is given as list
to ``repositories`` argument

"""
repository = audb.config.REPOSITORIES[repository_index]
if as_list:
repositories = [repository]
else:
repositories = repository
sourcery-ai[bot] marked this conversation as resolved.
Show resolved Hide resolved
sourcery-ai[bot] marked this conversation as resolved.
Show resolved Hide resolved
df = audb.available(repositories=repositories)
assert len(df) == 1
assert df.host.iloc[0] == repository.host
assert df.repository.iloc[0] == repository.name
assert df.index[0] == f"name{repository_index}"

def test_broken_database(self, repository_with_broken_database):
"""Test having a database only given as a folder."""
df = audb.available()
Expand Down
Loading