Skip to content

Commit 22955db

Browse files
committed
FIX: fix test failures on compression
Needed to eliminate compression setter due to the interdependencies between ioargs and compression.
1 parent 9fd8d13 commit 22955db

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pandas/io/formats/csvs.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
storage_options: StorageOptions = None,
5757
):
5858
self.obj = obj
59+
self.encoding = encoding or "utf-8"
5960

6061
if path_or_buf is None:
6162
path_or_buf = StringIO()
@@ -66,7 +67,7 @@ def __init__(
6667

6768
ioargs = get_filepath_or_buffer(
6869
path_or_buf,
69-
encoding=encoding,
70+
encoding=self.encoding,
7071
compression=self.compression,
7172
mode=mode,
7273
storage_options=storage_options,
@@ -76,13 +77,17 @@ def __init__(
7677
self.mode = ioargs.mode
7778

7879
# GH21227 internal compression is not used for non-binary handles.
79-
if compression and hasattr(self.path_or_buf, "write") and "b" not in self.mode:
80+
if (
81+
self.compression
82+
and hasattr(self.path_or_buf, "write")
83+
and "b" not in self.mode
84+
):
8085
warnings.warn(
8186
"compression has no effect when passing a non-binary object as input.",
8287
RuntimeWarning,
8388
stacklevel=2,
8489
)
85-
compression = None
90+
self.compression = None
8691

8792
self.sep = sep
8893
self.na_rep = na_rep
@@ -91,7 +96,6 @@ def __init__(
9196
self.header = header
9297
self.index = index
9398
self.index_label = index_label
94-
self.encoding = encoding or "utf-8"
9599
self.errors = errors
96100
self.quoting = quoting or csvlib.QUOTE_MINIMAL
97101
self.quotechar = quotechar

0 commit comments

Comments
 (0)