Skip to content

Commit df7c03e

Browse files
NicolasHugPaliC
authored andcommitted
Fix torchdata import error (#2242)
* Remove stuff * stuff * lint
1 parent 830b472 commit df7c03e

31 files changed

+51
-73
lines changed

torchtext/datasets/ag_news.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import HttpReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -65,6 +63,7 @@ def AG_NEWS(root: str, split: Union[Tuple[str], str]):
6563
raise ModuleNotFoundError(
6664
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
6765
)
66+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
6867

6968
url_dp = IterableWrapper([URL[split]])
7069
cache_dp = url_dp.on_disk_cache(

torchtext/datasets/amazonreviewfull.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -79,6 +77,7 @@ def AmazonReviewFull(root: str, split: Union[Tuple[str], str]):
7977
raise ModuleNotFoundError(
8078
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
8179
)
80+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
8281

8382
url_dp = IterableWrapper([URL])
8483
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/amazonreviewpolarity.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -76,6 +74,7 @@ def AmazonReviewPolarity(root: str, split: Union[Tuple[str], str]):
7674
raise ModuleNotFoundError(
7775
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
7876
)
77+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7978

8079
url_dp = IterableWrapper([URL])
8180
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/cc100.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os.path
22
from functools import partial
33

4-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
5-
from torchtext._download_hooks import HttpReader
4+
from torchtext._internal.module_utils import is_module_available
65
from torchtext.data.datasets_utils import (
76
_create_dataset_directory,
87
)
@@ -167,6 +166,11 @@ def CC100(root: str, language_code: str = "en"):
167166
"""
168167
if language_code not in VALID_CODES:
169168
raise ValueError(f"Invalid language code {language_code}")
169+
if not is_module_available("torchdata"):
170+
raise ModuleNotFoundError(
171+
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
172+
)
173+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
170174

171175
url = URL % language_code
172176
url_dp = IterableWrapper([url])

torchtext/datasets/cnndm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
from functools import partial
44
from typing import Union, Set, Tuple
55

6-
from torchdata.datapipes.iter import (
7-
FileOpener,
8-
IterableWrapper,
9-
OnlineReader,
10-
GDriveReader,
11-
)
126
from torchtext._internal.module_utils import is_module_available
137
from torchtext.data.datasets_utils import (
148
_wrap_split_argument,
@@ -141,6 +135,12 @@ def CNNDM(root: str, split: Union[Tuple[str], str]):
141135
raise ModuleNotFoundError(
142136
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
143137
)
138+
from torchdata.datapipes.iter import ( # noqa
139+
FileOpener,
140+
IterableWrapper,
141+
OnlineReader,
142+
GDriveReader,
143+
)
144144

145145
cnn_dp = _load_stories(root, "cnn", split)
146146
dailymail_dp = _load_stories(root, "dailymail", split)

torchtext/datasets/cola.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from functools import partial
44
from typing import Union, Tuple
55

6-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
7-
from torchtext._download_hooks import HttpReader
86
from torchtext._internal.module_utils import is_module_available
97
from torchtext.data.datasets_utils import _create_dataset_directory, _wrap_split_argument
108

@@ -76,6 +74,7 @@ def CoLA(root: str, split: Union[Tuple[str], str]):
7674
raise ModuleNotFoundError(
7775
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
7876
)
77+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7978

8079
url_dp = IterableWrapper([URL])
8180
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/conll2000chunking.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import HttpReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -68,6 +66,7 @@ def CoNLL2000Chunking(root: str, split: Union[Tuple[str], str]):
6866
raise ModuleNotFoundError(
6967
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
7068
)
69+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7170

7271
url_dp = IterableWrapper([URL[split]])
7372

torchtext/datasets/dbpedia.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -75,6 +73,7 @@ def DBpedia(root: str, split: Union[Tuple[str], str]):
7573
raise ModuleNotFoundError(
7674
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
7775
)
76+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7877

7978
url_dp = IterableWrapper([URL])
8079
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/enwik9.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
from functools import partial
33

4-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
5-
from torchtext._download_hooks import HttpReader
64
from torchtext._internal.module_utils import is_module_available
75
from torchtext.data.datasets_utils import _create_dataset_directory
86

@@ -50,6 +48,7 @@ def EnWik9(root: str):
5048
raise ModuleNotFoundError(
5149
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
5250
)
51+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
5352

5453
url_dp = IterableWrapper([URL])
5554
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/imdb.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from pathlib import Path
44
from typing import Tuple, Union
55

6-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
7-
from torchtext._download_hooks import HttpReader
86
from torchtext._internal.module_utils import is_module_available
97
from torchtext.data.datasets_utils import _create_dataset_directory
108
from torchtext.data.datasets_utils import _wrap_split_argument
@@ -89,6 +87,7 @@ def IMDB(root: str, split: Union[Tuple[str], str]):
8987
raise ModuleNotFoundError(
9088
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
9189
)
90+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
9291

9392
url_dp = IterableWrapper([URL])
9493

torchtext/datasets/iwslt2016.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
from functools import partial
33

4-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
5-
from torchtext._download_hooks import GDriveReader
64
from torchtext._internal.module_utils import is_module_available
75
from torchtext.data.datasets_utils import (
86
_clean_files,
@@ -219,6 +217,7 @@ def IWSLT2016(
219217
raise ModuleNotFoundError(
220218
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
221219
)
220+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
222221

223222
if not isinstance(language_pair, list) and not isinstance(language_pair, tuple):
224223
raise ValueError("language_pair must be list or tuple but got {} instead".format(type(language_pair)))

torchtext/datasets/iwslt2017.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
from functools import partial
33

4-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
5-
from torchtext._download_hooks import GDriveReader
64
from torchtext._internal.module_utils import is_module_available
75
from torchtext.data.datasets_utils import (
86
_clean_files,
@@ -184,6 +182,7 @@ def IWSLT2017(root=".data", split=("train", "valid", "test"), language_pair=("de
184182
raise ModuleNotFoundError(
185183
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
186184
)
185+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
187186

188187
valid_set = "dev2010"
189188
test_set = "tst2010"

torchtext/datasets/mnli.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import os
44
from functools import partial
55

6-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
7-
86
# we import HttpReader from _download_hooks so we can swap out public URLs
97
# with interal URLs when the dataset is used within Facebook
10-
from torchtext._download_hooks import HttpReader
8+
119
from torchtext._internal.module_utils import is_module_available
1210
from torchtext.data.datasets_utils import (
1311
_create_dataset_directory,
@@ -89,6 +87,7 @@ def MNLI(root, split):
8987
raise ModuleNotFoundError(
9088
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
9189
)
90+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
9291

9392
url_dp = IterableWrapper([URL])
9493
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/mrpc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from functools import partial
44
from typing import Union, Tuple
55

6-
from torchdata.datapipes.iter import FileOpener, HttpReader, IterableWrapper
76
from torchtext._internal.module_utils import is_module_available
87
from torchtext.data.datasets_utils import (
98
_wrap_split_argument,
@@ -67,6 +66,7 @@ def MRPC(root: str, split: Union[Tuple[str], str]):
6766
raise ModuleNotFoundError(
6867
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
6968
)
69+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7070

7171
url_dp = IterableWrapper([URL[split]])
7272
# cache data on-disk with sanity check

torchtext/datasets/multi30k.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader # noqa
7-
from torchtext._download_hooks import HttpReader
5+
# noqa
6+
87
from torchtext._internal.module_utils import is_module_available
98
from torchtext.data.datasets_utils import (
109
_wrap_split_argument,
@@ -89,6 +88,7 @@ def Multi30k(root: str, split: Union[Tuple[str], str], language_pair: Tuple[str]
8988
raise ModuleNotFoundError(
9089
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
9190
)
91+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
9292

9393
url_dp = IterableWrapper([URL[split]])
9494

torchtext/datasets/penntreebank.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from functools import partial
33
from typing import Tuple, Union
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader # noqa
7-
from torchtext._download_hooks import HttpReader
5+
# noqa
6+
87
from torchtext._internal.module_utils import is_module_available
98
from torchtext.data.datasets_utils import (
109
_wrap_split_argument,
@@ -70,6 +69,7 @@ def PennTreebank(root, split: Union[Tuple[str], str]):
7069
raise ModuleNotFoundError(
7170
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
7271
)
72+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
7373

7474
url_dp = IterableWrapper([URL[split]])
7575
cache_dp = url_dp.on_disk_cache(

torchtext/datasets/qnli.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import os
44
from functools import partial
55

6-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
7-
86
# we import HttpReader from _download_hooks so we can swap out public URLs
97
# with interal URLs when the dataset is used within Facebook
10-
from torchtext._download_hooks import HttpReader
8+
119
from torchtext._internal.module_utils import is_module_available
1210
from torchtext.data.datasets_utils import (
1311
_create_dataset_directory,
@@ -81,6 +79,7 @@ def QNLI(root, split):
8179
raise ModuleNotFoundError(
8280
"Package `torchdata` not found. Please install following instructions at `https://github.com/pytorch/data`"
8381
)
82+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
8483

8584
url_dp = IterableWrapper([URL])
8685
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/qqp.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
from functools import partial
33

4-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
5-
from torchtext._download_hooks import HttpReader
64
from torchtext._internal.module_utils import is_module_available
75
from torchtext.data.datasets_utils import _create_dataset_directory
86

@@ -48,6 +46,7 @@ def QQP(root: str):
4846
raise ModuleNotFoundError(
4947
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
5048
)
49+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
5150

5251
url_dp = IterableWrapper([URL])
5352
cache_dp = url_dp.on_disk_cache(

torchtext/datasets/rte.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import os
44
from functools import partial
55

6-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
7-
86
# we import HttpReader from _download_hooks so we can swap out public URLs
97
# with interal URLs when the dataset is used within Facebook
10-
from torchtext._download_hooks import HttpReader
8+
119
from torchtext._internal.module_utils import is_module_available
1210
from torchtext.data.datasets_utils import (
1311
_create_dataset_directory,
@@ -81,6 +79,7 @@ def RTE(root, split):
8179
raise ModuleNotFoundError(
8280
"Package `torchdata` not found. Please install following instructions at `https://github.com/pytorch/data`"
8381
)
82+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
8483

8584
url_dp = IterableWrapper([URL])
8685
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/sogounews.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import GDriveReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -79,6 +77,7 @@ def SogouNews(root: str, split: Union[Tuple[str], str]):
7977
raise ModuleNotFoundError(
8078
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
8179
)
80+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
8281

8382
url_dp = IterableWrapper([URL])
8483
cache_compressed_dp = url_dp.on_disk_cache(

torchtext/datasets/squad1.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from functools import partial
33
from typing import Union, Tuple
44

5-
from torchdata.datapipes.iter import FileOpener, IterableWrapper
6-
from torchtext._download_hooks import HttpReader
75
from torchtext._internal.module_utils import is_module_available
86
from torchtext.data.datasets_utils import (
97
_wrap_split_argument,
@@ -62,6 +60,7 @@ def SQuAD1(root: str, split: Union[Tuple[str], str]):
6260
raise ModuleNotFoundError(
6361
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
6462
)
63+
from torchdata.datapipes.iter import FileOpener, GDriveReader, HttpReader, IterableWrapper # noqa
6564

6665
url_dp = IterableWrapper([URL[split]])
6766
# cache data on-disk with sanity check

0 commit comments

Comments
 (0)