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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

0 commit comments

Comments
 (0)