Skip to content

Commit 72a5735

Browse files
authored
Raise FileNotFoundError when passing data_files that don't exist (#6155)
* raise filenotfound * only raise if no magic char in pattern * add test * use has_magic
1 parent 528b15f commit 72a5735

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/datasets/data_files.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
from functools import partial
4+
from glob import has_magic
45
from pathlib import Path, PurePath
56
from typing import Callable, Dict, List, Optional, Set, Tuple, Union
67

@@ -583,7 +584,8 @@ def from_patterns(
583584
)
584585
)
585586
except FileNotFoundError:
586-
pass
587+
if not has_magic(pattern):
588+
raise
587589
origin_metadata = _get_origin_metadata(data_files, download_config=download_config)
588590
return cls(data_files, origin_metadata)
589591

tests/test_data_files.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ def test_DataFilesList_from_patterns_locally_with_extra_files(complex_data_dir,
380380
assert len(data_files_list.origin_metadata) == 2
381381

382382

383+
def test_DataFilesList_from_patterns_raises_FileNotFoundError(complex_data_dir):
384+
with pytest.raises(FileNotFoundError):
385+
DataFilesList.from_patterns(["file_that_doesnt_exist.txt"], complex_data_dir)
386+
387+
383388
@pytest.mark.parametrize("pattern", _TEST_PATTERNS)
384389
def test_DataFilesDict_from_patterns_in_dataset_repository(
385390
hub_dataset_repo_path, hub_dataset_repo_patterns_results, pattern

0 commit comments

Comments
 (0)