Skip to content

Commit 63890ec

Browse files
committed
handle csv compression seperately
1 parent 2956103 commit 63890ec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pandas/io/formats/csvs.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def save(self):
133133
else:
134134
f, handles = _get_handle(self.path_or_buf, self.mode,
135135
encoding=encoding,
136-
compression=self.compression)
137-
close = True
136+
compression=None)
137+
close = True if self.compression is None else False
138138

139139
try:
140140
writer_kwargs = dict(lineterminator=self.line_terminator,
@@ -150,6 +150,16 @@ def save(self):
150150

151151
self._save()
152152

153+
# GH 17778 handles compression for byte strings.
154+
if not close and self.compression:
155+
f.close()
156+
with open(self.path_or_buf, 'r') as f:
157+
data = f.read()
158+
f, handles = _get_handle(self.path_or_buf, self.mode,
159+
encoding=encoding,
160+
compression=self.compression)
161+
f.write(data)
162+
close = True
153163
finally:
154164
if close:
155165
f.close()

0 commit comments

Comments
 (0)