Skip to content

Commit b625f08

Browse files
committed
handle PY2 differently
1 parent b833abd commit b625f08

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pandas/io/formats/csvs.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ def save(self):
152152

153153
finally:
154154
# GH 17778 handles zip compression for byte strings separately to
155-
# support Python 2
155+
# support Python 2, also allow compression file handle
156156
if not close and self.compression:
157157
f.close()
158-
with open(f.name, 'rb') as f:
159-
data = f.read().decode(encoding)
158+
if compat.PY2:
159+
_fh = open(f.name, 'r')
160+
else:
161+
_fh = open(f.name, 'r', encoding=encoding)
162+
with _fh:
163+
data = _fh.read()
160164
f, handles = _get_handle(f.name, self.mode,
161165
encoding=encoding,
162166
compression=self.compression)

0 commit comments

Comments
 (0)