From de72b34c32b6fed5220a9e3f6d0a5ff8d1e28218 Mon Sep 17 00:00:00 2001 From: Gokul Gunasekaran Date: Wed, 27 Mar 2024 14:29:27 -0700 Subject: [PATCH] removesuffix is not available 3.8, thus reverting the changes to rstrip (#1239) Summary: Without these changes, it will result in CI failing. When 3.8 support is dropped, this change can be landed. Fixes #{issue number} ### Changes - change removesuffix back to rstrip Pull Request resolved: https://github.com/pytorch/data/pull/1239 Reviewed By: r-barnes Differential Revision: D55433484 Pulled By: gokulavasan fbshipit-source-id: 75ca1341e88378b6b3134c401a82d66b0129e8f4 --- torchdata/datapipes/iter/util/bz2fileloader.py | 2 +- torchdata/datapipes/iter/util/xzfileloader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/torchdata/datapipes/iter/util/bz2fileloader.py b/torchdata/datapipes/iter/util/bz2fileloader.py index 7a45a8278..554b4d8d6 100644 --- a/torchdata/datapipes/iter/util/bz2fileloader.py +++ b/torchdata/datapipes/iter/util/bz2fileloader.py @@ -53,7 +53,7 @@ def __iter__(self) -> Iterator[Tuple[str, BufferedIOBase]]: pathname, data_stream = data try: extracted_fobj = bz2.open(data_stream, mode="rb") # type: ignore[call-overload] - new_pathname = pathname.removesuffix(".bz2") + new_pathname = pathname.rstrip(".bz2") # https://github.com/pytorch/data/issues/1240 yield new_pathname, StreamWrapper(extracted_fobj, data_stream, name=new_pathname) # type: ignore[misc] except Exception as e: warnings.warn(f"Unable to extract files from corrupted bzip2 stream {pathname} due to: {e}, abort!") diff --git a/torchdata/datapipes/iter/util/xzfileloader.py b/torchdata/datapipes/iter/util/xzfileloader.py index 528f7e4e3..f44dfaf3d 100644 --- a/torchdata/datapipes/iter/util/xzfileloader.py +++ b/torchdata/datapipes/iter/util/xzfileloader.py @@ -53,7 +53,7 @@ def __iter__(self) -> Iterator[Tuple[str, BufferedIOBase]]: pathname, data_stream = data try: extracted_fobj = lzma.open(data_stream, mode="rb") # type: ignore[call-overload] - new_pathname = pathname.removesuffix(".xz") + new_pathname = pathname.rstrip(".xz") # https://github.com/pytorch/data/issues/1240 yield new_pathname, StreamWrapper(extracted_fobj, data_stream, name=pathname) # type: ignore[misc] except Exception as e: warnings.warn(f"Unable to extract files from corrupted xz/lzma stream {pathname} due to: {e}, abort!")