Skip to content

Commit d5d7bb2

Browse files
marcenacpThe TensorFlow Datasets Authors
authored andcommitted
Add a heuristic to check that the user may have forgotten the config.
PiperOrigin-RevId: 654704293
1 parent 31218e1 commit d5d7bb2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tensorflow_datasets/core/read_only_builder.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ def _find_builder_dir(name: str, **builder_kwargs: Any) -> str | None:
363363
if not all_builder_dirs:
364364
all_dirs_str = '\n\t- '.join([''] + [str(dir) for dir in all_data_dirs])
365365
error_msg = f'No registered data_dirs were found in:{all_dirs_str}\n'
366+
367+
# If the dataset root_dir exists, a common error is that the config name
368+
# was not specified. So we list the possible configs and display them.
369+
possible_configs = _list_possible_configs(name, all_data_dirs)
370+
if possible_configs:
371+
configs = '\n\t- '.join([''] + list(possible_configs))
372+
error_msg = (
373+
f'However, a folder for "{name.name}" does exist. Is it possible that'
374+
' you specified the wrong config? You can add a config by replacing'
375+
f' `tfds.load({name.name})` by `tfds.load("{name.name}/my_config")`.'
376+
f' Possible configs are:{configs}\n'
377+
)
378+
366379
error_utils.add_context(error_msg)
367380
return None
368381

@@ -385,6 +398,19 @@ def _find_builder_dir(name: str, **builder_kwargs: Any) -> str | None:
385398
return all_builder_dirs.pop()
386399

387400

401+
def _list_possible_configs(
402+
name: naming.DatasetName, all_data_dirs: set[epath.PathLike]
403+
) -> Sequence[str]:
404+
configs = []
405+
for data_dir in all_data_dirs:
406+
root_dir = epath.Path(data_dir) / name.name
407+
if root_dir.exists():
408+
for path in root_dir.iterdir():
409+
if path.is_dir():
410+
configs.append(path.name)
411+
return configs
412+
413+
388414
def _get_dataset_dir(
389415
builder_dir: epath.Path,
390416
*,

0 commit comments

Comments
 (0)