-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix inferring module for unsupported data files #5787
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
074375a
Test infer module for unsupported data files
albertvillanova 244c4e5
Fix infer module functions for unsupported files
albertvillanova 207268e
Fix dataset module factories without script
albertvillanova 650141d
Make sure split_modules is not empty due to empty data_files
albertvillanova 6e4997a
Revert "Make sure split_modules is not empty due to empty data_files"
albertvillanova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,7 @@ def infer_module_for_data_files( | |
return _EXTENSION_TO_MODULE[ext] | ||
elif ext == "zip": | ||
return infer_module_for_data_files_in_archives(data_files_list, use_auth_token=use_auth_token) | ||
return None, {} | ||
|
||
|
||
def infer_module_for_data_files_in_archives( | ||
|
@@ -404,6 +405,7 @@ def infer_module_for_data_files_in_archives( | |
most_common = extensions_counter.most_common(1)[0][0] | ||
if most_common in _EXTENSION_TO_MODULE: | ||
return _EXTENSION_TO_MODULE[most_common] | ||
return None, {} | ||
|
||
|
||
@dataclass | ||
|
@@ -632,14 +634,14 @@ def get_module(self) -> DatasetModule: | |
base_path=base_path, | ||
allowed_extensions=ALL_ALLOWED_EXTENSIONS, | ||
) | ||
module_names = { | ||
key: infer_module_for_data_files(data_files_list) for key, data_files_list in data_files.items() | ||
split_modules = { | ||
split: infer_module_for_data_files(data_files_list) for split, data_files_list in data_files.items() | ||
} | ||
if len(set(list(zip(*module_names.values()))[0])) > 1: | ||
raise ValueError(f"Couldn't infer the same data file format for all splits. Got {module_names}") | ||
module_name, builder_kwargs = next(iter(module_names.values())) | ||
module_name, builder_kwargs = next(iter(split_modules.values())) | ||
if any((module_name, builder_kwargs) != split_module for split_module in split_modules.values()): | ||
raise ValueError(f"Couldn't infer the same data file format for all splits. Got {split_modules}") | ||
if not module_name: | ||
raise FileNotFoundError(f"No data files or dataset script found in {self.path}") | ||
raise FileNotFoundError(f"No (supported) data files or dataset script found in {self.path}") | ||
# Collect metadata files if the module supports them | ||
if self.data_files is None and module_name in _MODULE_SUPPORTS_METADATA and patterns != DEFAULT_PATTERNS_ALL: | ||
try: | ||
|
@@ -772,15 +774,15 @@ def get_module(self) -> DatasetModule: | |
base_path=self.data_dir, | ||
allowed_extensions=ALL_ALLOWED_EXTENSIONS, | ||
) | ||
module_names = { | ||
key: infer_module_for_data_files(data_files_list, use_auth_token=self.download_config.use_auth_token) | ||
for key, data_files_list in data_files.items() | ||
split_modules = { | ||
split: infer_module_for_data_files(data_files_list, use_auth_token=self.download_config.use_auth_token) | ||
for split, data_files_list in data_files.items() | ||
} | ||
if len(set(list(zip(*module_names.values()))[0])) > 1: | ||
raise ValueError(f"Couldn't infer the same data file format for all splits. Got {module_names}") | ||
module_name, builder_kwargs = next(iter(module_names.values())) | ||
module_name, builder_kwargs = next(iter(split_modules.values())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if any((module_name, builder_kwargs) != split_module for split_module in split_modules.values()): | ||
raise ValueError(f"Couldn't infer the same data file format for all splits. Got {split_modules}") | ||
if not module_name: | ||
raise FileNotFoundError(f"No data files or dataset script found in {self.name}") | ||
raise FileNotFoundError(f"No (supported) data files or dataset script found in {self.name}") | ||
# Collect metadata files if the module supports them | ||
if self.data_files is None and module_name in _MODULE_SUPPORTS_METADATA and patterns != DEFAULT_PATTERNS_ALL: | ||
try: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check that i split_modules is not empty ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review, @lhoestq.
I think it can only be empty if the user passes
data_files={}
, otherwise there are 2 options: either it is not empty or an exception is raised.split_modules
is derived fromdata_files
, which is instance ofDataFilesDict.from_local_or_remote
withpatterns
patterns
is derived either fromsanitize_patterns
orget_data_patterns_locally
sanitize_patterns
can only return an empty dict if the user passesdata_files={}
get_data_patterns_locally
can only return a non-empty dict or raise aEmptyDatasetError
I think the validation of
data_files={}
should be elsewhere though. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe changing?
to
This way, we are sure
split_modules
is never empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea indeed, probably in load_dataset_builder ?
I think it's better if it raises an error rather than trying to make it run with data files that were not requested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge then :)