@@ -56,6 +56,7 @@ def __init__(
56
56
storage_options : StorageOptions = None ,
57
57
):
58
58
self .obj = obj
59
+ self .encoding = encoding or "utf-8"
59
60
60
61
if path_or_buf is None :
61
62
path_or_buf = StringIO ()
@@ -66,7 +67,7 @@ def __init__(
66
67
67
68
ioargs = get_filepath_or_buffer (
68
69
path_or_buf ,
69
- encoding = encoding ,
70
+ encoding = self . encoding ,
70
71
compression = self .compression ,
71
72
mode = mode ,
72
73
storage_options = storage_options ,
@@ -76,13 +77,17 @@ def __init__(
76
77
self .mode = ioargs .mode
77
78
78
79
# 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
+ ):
80
85
warnings .warn (
81
86
"compression has no effect when passing a non-binary object as input." ,
82
87
RuntimeWarning ,
83
88
stacklevel = 2 ,
84
89
)
85
- compression = None
90
+ self . compression = None
86
91
87
92
self .sep = sep
88
93
self .na_rep = na_rep
@@ -91,7 +96,6 @@ def __init__(
91
96
self .header = header
92
97
self .index = index
93
98
self .index_label = index_label
94
- self .encoding = encoding or "utf-8"
95
99
self .errors = errors
96
100
self .quoting = quoting or csvlib .QUOTE_MINIMAL
97
101
self .quotechar = quotechar
0 commit comments