Skip to content

Commit 57eba0a

Browse files
authored
pass through "mode" via compression args
1 parent 2531ee0 commit 57eba0a

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

pandas/core/generic.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,6 @@ def to_json(
23452345
default_handler: Callable[[Any], JSONSerializable] | None = None,
23462346
lines: bool_t = False,
23472347
compression: CompressionOptions = "infer",
2348-
mode: str = "w",
23492348
index: bool_t = True,
23502349
indent: int | None = None,
23512350
storage_options: StorageOptions = None,
@@ -2607,7 +2606,6 @@ def to_json(
26072606
default_handler=default_handler,
26082607
lines=lines,
26092608
compression=compression,
2610-
mode=mode,
26112609
index=index,
26122610
indent=indent,
26132611
storage_options=storage_options,
@@ -2949,7 +2947,6 @@ def to_pickle(
29492947
self,
29502948
path,
29512949
compression: CompressionOptions = "infer",
2952-
mode: str = "wb",
29532950
protocol: int = pickle.HIGHEST_PROTOCOL,
29542951
storage_options: StorageOptions = None,
29552952
) -> None:
@@ -3007,7 +3004,6 @@ def to_pickle(
30073004
self,
30083005
path,
30093006
compression=compression,
3010-
mode=mode,
30113007
protocol=protocol,
30123008
storage_options=storage_options,
30133009
)

pandas/io/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,12 @@ def get_handle(
763763

764764
# TAR Encoding
765765
elif compression == "tar":
766+
if "mode" not in compression_args:
767+
compression_args["mode"] = ioargs.mode
766768
if is_path:
767-
handle = _BytesTarFile.open(name=handle, mode=ioargs.mode)
769+
handle = _BytesTarFile.open(name=handle, **compression_args)
768770
else:
769-
handle = _BytesTarFile.open(fileobj=handle, mode=ioargs.mode)
771+
handle = _BytesTarFile.open(fileobj=handle, **compression_args)
770772
if handle.mode == "r":
771773
handles.append(handle)
772774
files = handle.getnames()

pandas/tests/io/test_compression.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ def flip(my_dict: dict):
3030
)
3131
@pytest.mark.parametrize("method", ["to_pickle", "to_json", "to_csv"])
3232
def test_compression_size(obj, method, compression_only):
33-
kwargs = {}
34-
3533
if compression_only == "tar":
36-
kwargs["mode"] = "w:gz"
34+
compression_only = {"method": "tar", "mode": "w:gz"}
3735

3836
with tm.ensure_clean() as path:
39-
getattr(obj, method)(path, compression=compression_only, **kwargs)
37+
getattr(obj, method)(path, compression=compression_only)
4038
compressed_size = os.path.getsize(path)
4139
getattr(obj, method)(path, compression=None)
4240
uncompressed_size = os.path.getsize(path)

0 commit comments

Comments
 (0)