Got "AttributeError: 'xPath' object has no attribute 'read'" when loading an excel dataset with my own code
NONE
What's more, the downloaded data is actually a folder instead of an excel file.
2022-08-19T05:56:41Z
https://github.com/huggingface/datasets/issues/4862#issuecomment-1220282039
https://api.github.com/repos/huggingface/datasets/issues/4862
IC_kwDODunzps5IvAa3
https://api.github.com/repos/huggingface/datasets/issues/comments/1220282039/reactions
2022-08-19T05:56:41Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1220282039
https://avatars.githubusercontent.com/u/38536635?v=4
https://api.github.com/users/yana-xuyan/events{/privacy}
https://api.github.com/users/yana-xuyan/followers
https://api.github.com/users/yana-xuyan/following{/other_user}
https://api.github.com/users/yana-xuyan/gists{/gist_id}
https://github.com/yana-xuyan
yana-xuyan
MDQ6VXNlcjM4NTM2NjM1
https://api.github.com/users/yana-xuyan/orgs
https://api.github.com/users/yana-xuyan/received_events
https://api.github.com/users/yana-xuyan/repos
https://api.github.com/users/yana-xuyan/starred{/owner}{/repo}
https://api.github.com/users/yana-xuyan/subscriptions
User
https://api.github.com/users/yana-xuyan
public
NONE
Hi hi, instead of using `download_and_extract` function, I only use `download` function: `base_dir = Path(dl_manager.download(urls))`. It turns out that the code works for `datasets==2.2.2`, however, it doesn't work with `datasets==2.4.0`. 
2022-08-21T07:10:51Z
https://github.com/huggingface/datasets/issues/4862#issuecomment-1221484611
https://api.github.com/repos/huggingface/datasets/issues/4862
IC_kwDODunzps5IzmBD
https://api.github.com/repos/huggingface/datasets/issues/comments/1221484611/reactions
2022-08-21T07:10:51Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1221484611
https://avatars.githubusercontent.com/u/38536635?v=4
https://api.github.com/users/yana-xuyan/events{/privacy}
https://api.github.com/users/yana-xuyan/followers
https://api.github.com/users/yana-xuyan/following{/other_user}
https://api.github.com/users/yana-xuyan/gists{/gist_id}
https://github.com/yana-xuyan
yana-xuyan
MDQ6VXNlcjM4NTM2NjM1
https://api.github.com/users/yana-xuyan/orgs
https://api.github.com/users/yana-xuyan/received_events
https://api.github.com/users/yana-xuyan/repos
https://api.github.com/users/yana-xuyan/starred{/owner}{/repo}
https://api.github.com/users/yana-xuyan/subscriptions
User
https://api.github.com/users/yana-xuyan
public
MEMBER
Hi @yana-xuyan, thanks for reporting.

Indeed you already found the answer: an Excel file should be just downloaded and not downloaded-and-extracted.

The reason why is that if you call also extract, our library will try to infer the compression format (and extract it). And Excel files are viewed as ZIP files and extracted as so (into a directory). This is because the Office Open XML is indeed a zipped file under the hood): https://en.wikipedia.org/wiki/Office_Open_XML
> Office Open XML (also informally known as OOXML) is a **zipped**, XML-based file format
```python
import zipfile

zipfile.is_zipfile("filename.xlsx")
```
returns `True`.
2022-08-22T06:57:14Z
https://github.com/huggingface/datasets/issues/4862#issuecomment-1221930116
https://api.github.com/repos/huggingface/datasets/issues/4862
IC_kwDODunzps5I1SyE
https://api.github.com/repos/huggingface/datasets/issues/comments/1221930116/reactions
2022-08-22T06:57:47Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1221930116
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
NONE
Hi @albertvillanova, thank you for your reply! Do you have any clue on why the same error still exists with `datasets==2.4.0` even after I don't extract the downloaded file? FYI, if I downgrade to `datasets==2.2.2`, the code works fine.
2022-08-22T08:53:08Z
https://github.com/huggingface/datasets/issues/4862#issuecomment-1222053433
https://api.github.com/repos/huggingface/datasets/issues/4862
IC_kwDODunzps5I1w45
https://api.github.com/repos/huggingface/datasets/issues/comments/1222053433/reactions
2022-08-22T08:53:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1222053433
https://avatars.githubusercontent.com/u/38536635?v=4
https://api.github.com/users/yana-xuyan/events{/privacy}
https://api.github.com/users/yana-xuyan/followers
https://api.github.com/users/yana-xuyan/following{/other_user}
https://api.github.com/users/yana-xuyan/gists{/gist_id}
https://github.com/yana-xuyan
yana-xuyan
MDQ6VXNlcjM4NTM2NjM1
https://api.github.com/users/yana-xuyan/orgs
https://api.github.com/users/yana-xuyan/received_events
https://api.github.com/users/yana-xuyan/repos
https://api.github.com/users/yana-xuyan/starred{/owner}{/repo}
https://api.github.com/users/yana-xuyan/subscriptions
User
https://api.github.com/users/yana-xuyan
public
MEMBER
I guess this has to do with the cache: you should remove the previously-wrongly generated directory from the cache; otherwise `datasets` tries to re-use it.
2022-08-22T09:36:19Z
https://github.com/huggingface/datasets/issues/4862#issuecomment-1222103793
https://api.github.com/repos/huggingface/datasets/issues/4862
IC_kwDODunzps5I19Lx
https://api.github.com/repos/huggingface/datasets/issues/comments/1222103793/reactions
2022-08-22T09:36:19Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1222103793
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
## Describe the bug
A clear and concise description of what the bug is.

## Steps to reproduce the bug
```python
# Sample code to reproduce the bug
# The dataset function is as follows：
from pathlib import Path
from typing import Dict, List, Tuple

import datasets
import pandas as pd

_CITATION = """\
"""

_DATASETNAME = "jadi_ide"

_DESCRIPTION = """\
"""

_HOMEPAGE = ""
_LICENSE = "Unknown"
_URLS = {
    _DATASETNAME: "https://github.com/fathanick/Javanese-Dialect-Identification-from-Twitter-Data/raw/main/Update 16K_Dataset.xlsx",
}
_SOURCE_VERSION = "1.0.0"


class JaDi_Ide(datasets.GeneratorBasedBuilder):

    SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)

    BUILDER_CONFIGS = [
        NusantaraConfig(
            name="jadi_ide_source",
            version=SOURCE_VERSION,
            description="JaDi-Ide source schema",
            schema="source",
            subset_id="jadi_ide",
        ),
    ]

    DEFAULT_CONFIG_NAME = "source"

    def _info(self) -> datasets.DatasetInfo:
        if self.config.schema == "source":
            features = datasets.Features(
                {
                    "id": datasets.Value("string"), 
                    "text": datasets.Value("string"), 
                    "label": datasets.Value("string")
                }
            )

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        """Returns SplitGenerators."""
        # Dataset does not have predetermined split, putting all as TRAIN
        urls = _URLS[_DATASETNAME]
        base_dir = Path(dl_manager.download_and_extract(urls))
        data_files = {"train": base_dir}

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": data_files["train"],
                    "split": "train",
                },
            ),
        ]

    def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
        """Yields examples as (key, example) tuples."""
        df = pd.read_excel(filepath, engine='openpyxl')
        df.columns = ["id", "text", "label"]

        if self.config.schema == "source":
            for row in df.itertuples():
                ex = {
                    "id": str(row.id),
                    "text": row.text,
                    "label": row.label,
                }
                yield row.id, ex

```

## Expected results
Expecting to load the dataset smoothly.

## Actual results
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/load.py", line 1751, in load_dataset
    use_auth_token=use_auth_token,
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/builder.py", line 705, in download_and_prepare
    dl_manager=dl_manager, verify_infos=verify_infos, **download_and_prepare_kwargs
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/builder.py", line 1227, in _download_and_prepare
    super()._download_and_prepare(dl_manager, verify_infos, check_duplicate_keys=verify_infos)
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/builder.py", line 793, in _download_and_prepare
    self._prepare_split(split_generator, **prepare_split_kwargs)
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/builder.py", line 1216, in _prepare_split
    desc=f"Generating {split_info.name} split",
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/tqdm/std.py", line 1195, in __iter__
    for obj in iterable:
  File "/home/xuyan/.cache/huggingface/modules/datasets_modules/datasets/jadi_ide/7a539f2b6f726defea8fbe36ceda17bae66c370f6d6c418e3a08d760ebef7519/jadi_ide.py", line 107, in _generate_examples
    df = pd.read_excel(filepath, engine='openpyxl')
  File "/home/xuyan/anaconda3/lib/python3.7/site-packages/datasets/download/streaming_download_manager.py", line 701, in xpandas_read_excel
    return pd.read_excel(BytesIO(filepath_or_buffer.read()), **kwargs)
AttributeError: 'xPath' object has no attribute 'read'

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version: 2.4.0
- Platform: Linux-4.15.0-142-generic-x86_64-with-debian-stretch-sid
- Python version: 3.7.4
- PyArrow version: 9.0.0
- Pandas version: 0.25.1
