Skip to content

Guard against duplicate builder_kwargs/config_kwargs in load_dataset_… #7622

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

Closed
Closed
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
8 changes: 8 additions & 0 deletions src/datasets/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,14 @@ def load_dataset_builder(
storage_options: Optional[dict] = None,
**config_kwargs,
) -> DatasetBuilder:
# Error if builder_kwargs and config_kwargs share any keys
if "builder_kwargs" in config_kwargs and "config_kwargs" in config_kwargs:
bk = config_kwargs["builder_kwargs"]
ck = config_kwargs["config_kwargs"]
overlap = set(bk) & set(ck)
if overlap:
raise TypeError(f"Duplicate keys in builder_kwargs and config_kwargs: {overlap}")

"""Load a dataset builder which can be used to:

- Inspect general information that is required to build a dataset (cache directory, config, dataset info, features, data files, etc.)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_load_duplicate_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from datasets.load import load_dataset_builder

def test_duplicate_builder_and_config_kwargs():
builder_kwargs = {"foo-key": 1}
config_kwargs = {"foo-key": 2}
with pytest.raises(TypeError) as excinfo:
load_dataset_builder(
"csv",
builder_kwargs=builder_kwargs,
config_kwargs=config_kwargs,
)
msg = str(excinfo.value).lower()
assert "duplicate keys" in msg
assert "builder_kwargs" in msg
assert "config_kwargs" in msg