GitHub issue #4428: Errors when building dummy data if you use nested _URLS
State: closed | Created: 2022-05-31T16:10:57Z

## Describe the bug
When making dummy data with the `datasets-cli dummy_data` tool,
an error will be raised if you use a nested _URLS in your dataset script.


Traceback (most recent call last):
  File "/home/name/LCCC/datasets/src/datasets/commands/datasets_cli.py", line 43, in <module>
    main()
  File "/home/name/LCCC/datasets/src/datasets/commands/datasets_cli.py", line 39, in main
    service.run()
  File "/home/name/LCCC/datasets/src/datasets/commands/dummy_data.py", line 311, in run
    self._autogenerate_dummy_data(
  File "/home/name/LCCC/datasets/src/datasets/commands/dummy_data.py", line 337, in _autogenerate_dummy_data
    dataset_builder._split_generators(dl_manager)
  File "/home/name/.cache/huggingface/modules/datasets_modules/datasets/personal_dialog/559332bced5eeafa7f7efc2a7c10ce02cee2a8116bbab4611c35a50ba2715b77/personal_dialog.py", line 108, in _split_generators
    data_dir = dl_manager.download_and_extract(urls)
  File "/home/name/LCCC/datasets/src/datasets/commands/dummy_data.py", line 56, in download_and_extract
    dummy_output = self.mock_download_manager.download(url_or_urls)
  File "/home/name/LCCC/datasets/src/datasets/download/mock_download_manager.py", line 130, in download
    return self.download_and_extract(data_url)
  File "/home/name/LCCC/datasets/src/datasets/download/mock_download_manager.py", line 122, in download_and_extract
    return self.create_dummy_data_dict(dummy_file, data_url)
  File "/home/name/LCCC/datasets/src/datasets/download/mock_download_manager.py", line 165, in create_dummy_data_dict
    if isinstance(first_value, str) and len(set(dummy_data_dict.values())) < len(dummy_data_dict.values()):
TypeError: unhashable type: 'list'


## Steps to reproduce the bug

You can use my dataset script implemented here:
https://github.com/silverriver/datasets/blob/2ecd36760c40b8e29b1137cd19b5bad0e19c76fd/datasets/personal_dialog/personal_dialog.py

```python
datasets_cli dummy_data datasets/personal_dialog --auto_generate
```

You can change https://github.com/silverriver/datasets/blob/2ecd36760c40b8e29b1137cd19b5bad0e19c76fd/datasets/personal_dialog/personal_dialog.py#L54
to 

```
"train": "https://huggingface.co/datasets/silver/personal_dialog/resolve/main/dev_random.jsonl.gz"
```

before runing the above script to avoid downloading a large training data.


## Expected results
The dummy data should be generated

## Actual results
An error is raised.

It seems that in https://github.com/huggingface/datasets/blob/12540dd75015678ec6019f258d811ee107439a73/src/datasets/download/mock_download_manager.py#L165
We only check if the first item of dummy_data_dict.values() is str.
However, dummy_data_dict.values() may have the type of [str, list, list].
A simple fix would be changing https://github.com/huggingface/datasets/blob/12540dd75015678ec6019f258d811ee107439a73/src/datasets/download/mock_download_manager.py#L165 to

```python
if all([isinstance(value, str) for value in dummy_data_dict.values()]) and len(set(dummy_data_dict.values())) < len(dummy_data_dict.values()):
```

But I don't know if this kinds of change may bring any side effect since I am not sure about the detail logic here.

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version:
- Platform: Linux
- Python version: Python 3.9.10
- PyArrow version: 7.0.0