Skip to content

Renaming IoPathFileLoader to IoPathFileOpener #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/test_local_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
FileOpener,
HashChecker,
IoPathFileLister,
IoPathFileLoader,
IoPathFileOpener,
IoPathSaver,
IterableWrapper,
JsonParser,
Expand Down Expand Up @@ -539,7 +539,7 @@ def test_io_path_file_lister_iterdatapipe(self):
@skipIfNoIoPath
def test_io_path_file_loader_iterdatapipe(self):
datapipe1 = IoPathFileLister(root=self.temp_sub_dir.name)
datapipe2 = IoPathFileLoader(datapipe1)
datapipe2 = IoPathFileOpener(datapipe1)

# check contents of file match
for _, f in datapipe2:
Expand All @@ -548,7 +548,7 @@ def test_io_path_file_loader_iterdatapipe(self):
# Reset Test: Ensure the resulting streams are still readable after the DataPipe is reset/exhausted
self._write_text_files()
lister_dp = FileLister(self.temp_dir.name, "*.text")
iopath_file_loader_dp = IoPathFileLoader(lister_dp, mode="rb")
iopath_file_loader_dp = IoPathFileOpener(lister_dp, mode="rb")

n_elements_before_reset = 2
res_before_reset, res_after_reset = reset_after_n_next_calls(iopath_file_loader_dp, n_elements_before_reset)
Expand Down
2 changes: 2 additions & 0 deletions torchdata/datapipes/iter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from torchdata.datapipes.iter.load.iopath import (
IoPathFileListerIterDataPipe as IoPathFileLister,
IoPathFileLoaderIterDataPipe as IoPathFileLoader,
IoPathFileOpenerIterDataPipe as IoPathFileOpener,
IoPathSaverIterDataPipe as IoPathSaver,
)

Expand Down Expand Up @@ -107,6 +108,7 @@
"IndexAdder",
"IoPathFileLister",
"IoPathFileLoader",
"IoPathFileOpener",
"IoPathSaver",
"IterDataPipe",
"IterKeyZipper",
Expand Down
14 changes: 13 additions & 1 deletion torchdata/datapipes/iter/load/iopath.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Facebook, Inc. and its affiliates.
import os
import warnings

from typing import Any, Callable, Iterator, List, Optional, Tuple, Union

Expand Down Expand Up @@ -82,7 +83,18 @@ def __iter__(self) -> Iterator[str]:

@functional_datapipe("load_file_by_iopath")
class IoPathFileLoaderIterDataPipe(IterDataPipe[Tuple[str, StreamWrapper]]):
r""":class:`IoPathFileLoaderIterDataPipe`.
def __new__(cls, source_datapipe: IterDataPipe[str], mode: str = "r", pathmgr=None):
warnings.warn(
"IoPathFileLoaderIterDataPipe and its functional API has been renamed and will be removed "
"from this package. Please use 'IoPathFileOpenerIterDataPipe' instead.",
DeprecationWarning,
)
return IoPathFileOpenerIterDataPipe(source_datapipe=source_datapipe, mode=mode, pathmgr=pathmgr)


@functional_datapipe("open_file_by_iopath")
class IoPathFileOpenerIterDataPipe(IterDataPipe[Tuple[str, StreamWrapper]]):
r""":class:`IoPathFileOpenerIterDataPipe`.

Iterable DataPipe to open files from input datapipe which contains pathnames or URLs,
and yields a tuple of pathname and opened file stream.
Expand Down