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

Make inspect.get_dataset_config_names always return a non-empty list #3159

Merged
merged 17 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/datasets/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ def _create_builder_config(self, name=None, custom_features=None, **config_kwarg
@utils.memoize()
def builder_configs(cls):
"""Pre-defined list of configurations for this builder class."""
config_dict = {config.name: config for config in cls.BUILDER_CONFIGS}
if len(config_dict) != len(cls.BUILDER_CONFIGS):
configs = {config.name: config for config in cls.BUILDER_CONFIGS}
if len(configs) != len(cls.BUILDER_CONFIGS):
names = [config.name for config in cls.BUILDER_CONFIGS]
raise ValueError("Names in BUILDER_CONFIGS must not be duplicated. Got %s" % names)
return config_dict
return configs

@property
def cache_dir(self):
Expand Down
9 changes: 4 additions & 5 deletions src/datasets/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .features import Features
from .hf_api import HfApi
from .load import import_main_class, load_dataset_builder, prepare_module
from .load import dataset_module_factory, import_main_class, load_dataset_builder, prepare_module
from .utils import DownloadConfig
from .utils.download_manager import GenerateMode
from .utils.logging import get_logger
Expand Down Expand Up @@ -194,9 +194,8 @@ def get_dataset_config_names(
download_kwargs: optional attributes for DownloadConfig() which will override the attributes in download_config if supplied,
for example ``use_auth_token``
"""
module_path, _ = prepare_module(
dataset_module = dataset_module_factory(
path,
dataset=True,
revision=revision,
download_config=download_config,
download_mode=download_mode,
Expand All @@ -205,8 +204,8 @@ def get_dataset_config_names(
data_files=data_files,
**download_kwargs,
)
builder_cls = import_main_class(module_path, dataset=True)
return list(builder_cls.builder_configs.keys())
builder_cls = import_main_class(dataset_module.module_path)
return list(builder_cls.builder_configs.keys()) or [dataset_module.builder_kwargs.get("name", "default")]


def get_dataset_split_names(
Expand Down
7 changes: 3 additions & 4 deletions src/datasets/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,14 +1438,13 @@ def load_dataset_builder(
if use_auth_token is not None:
download_config = download_config.copy() if download_config else DownloadConfig()
download_config.use_auth_token = use_auth_token
dataset_module_factory_result = dataset_module_factory(
dataset_module = dataset_module_factory(
path, revision=revision, download_config=download_config, download_mode=download_mode, data_files=data_files
)

# Get dataset builder class from the processing script
dataset_module = dataset_module_factory_result.module_path
builder_cls = import_main_class(dataset_module)
builder_kwargs = dataset_module_factory_result.builder_kwargs
builder_cls = import_main_class(dataset_module.module_path)
builder_kwargs = dataset_module.builder_kwargs
data_files = builder_kwargs.pop("data_files", data_files)
name = builder_kwargs.pop("name", name)
hash = builder_kwargs.pop("hash")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from datasets import get_dataset_config_names


@pytest.mark.parametrize(
"path, expected",
[("squad", "plain_text"), ("acronym_identification", "default"), ("Check/region_1", "Check___region_1")],
)
def test_get_dataset_config_names(path, expected):
config_names = get_dataset_config_names(path)
assert expected in config_names