Skip to content

Commit c098c8f

Browse files
committed
CSVFormatter: process encoding in init for consistency
1 parent 8411eb2 commit c098c8f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pandas/io/formats/csvs.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
5555
self.index = index
5656
self.index_label = index_label
5757
self.mode = mode
58+
if encoding is None:
59+
encoding = 'ascii' if compat.PY2 else 'utf-8'
5860
self.encoding = encoding
5961
self.compression = _infer_compression(self.path_or_buf, compression)
6062

@@ -129,14 +131,9 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
129131
self.nlevels = 0
130132

131133
def save(self):
132-
# create the writer & save
133-
if self.encoding is None:
134-
if compat.PY2:
135-
encoding = 'ascii'
136-
else:
137-
encoding = 'utf-8'
138-
else:
139-
encoding = self.encoding
134+
"""
135+
Create the writer & save
136+
"""
140137

141138
# GH 21227 internal compression is not used when file-like passed.
142139
import logging

0 commit comments

Comments
 (0)