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

Raise error on bad split name #6626

Merged
merged 2 commits into from
Jan 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
python -m spacy download fr_core_news_sm
- name: Install dependencies (latest versions)
if: ${{ matrix.deps_versions == 'deps-latest' }}
run: pip install --upgrade pyarrow huggingface-hub dill
run: pip install --upgrade pyarrow huggingface-hub "dill<0.3.8"
- name: Install dependencies (minimum versions)
if: ${{ matrix.deps_versions != 'deps-latest' }}
run: pip install pyarrow==8.0.0 huggingface-hub==0.19.4 transformers dill==0.3.1.1
Expand Down
3 changes: 3 additions & 0 deletions src/datasets/data_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import config
from .download import DownloadConfig
from .download.streaming_download_manager import _prepare_path_and_storage_options, xbasename, xjoin
from .naming import _split_re
from .splits import Split
from .utils import logging
from .utils import tqdm as hf_tqdm
Expand Down Expand Up @@ -247,6 +248,8 @@ def _get_data_files_patterns(pattern_resolver: Callable[[str], List[str]]) -> Di
string_to_dict(xbasename(p), glob_pattern_to_regex(xbasename(split_pattern)))["split"]
for p in data_files
}
if any(not re.match(_split_re, split) for split in splits):
raise ValueError(f"Split name should match '{_split_re}'' but got '{splits}'.")
sorted_splits = [str(split) for split in DEFAULT_SPLITS if split in splits] + sorted(
splits - set(DEFAULT_SPLITS)
)
Expand Down
5 changes: 5 additions & 0 deletions src/datasets/utils/metadata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import textwrap
from collections import Counter
from itertools import groupby
Expand All @@ -10,6 +11,7 @@

from ..config import METADATA_CONFIGS_FIELD
from ..info import DatasetInfo, DatasetInfosDict
from ..naming import _split_re
from ..utils.logging import get_logger
from .deprecation_utils import deprecated

Expand Down Expand Up @@ -155,6 +157,8 @@ def _raise_if_data_files_field_not_valid(metadata_config: dict):
- train/part2/*
- split: test
path: test/*

PS: some symbols like dashes '-' are not allowed in split names
"""
)
if not isinstance(yaml_data_files, (list, str)):
Expand All @@ -167,6 +171,7 @@ def _raise_if_data_files_field_not_valid(metadata_config: dict):
and not (
len(yaml_data_files_item) == 2
and "split" in yaml_data_files_item
and re.match(_split_re, yaml_data_files_item["split"])
and isinstance(yaml_data_files_item.get("path"), (str, list))
)
):
Expand Down
Loading