Skip to content

Commit 6accf04

Browse files
committed
add warning when passing file handle with compression flag
1 parent 9567900 commit 6accf04

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

pandas/io/formats/csvs.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def save(self):
142142
elif hasattr(self.path_or_buf, 'write'):
143143
f = self.path_or_buf
144144
close = False
145+
if self.compression:
146+
import warnings
147+
msg = ("compression has no effect when passing file-like "
148+
"object as input.")
149+
warnings.warn(msg, RuntimeWarning, stacklevel=2)
145150
else:
146151
f, handles = _get_handle(self.path_or_buf, self.mode,
147152
encoding=encoding,
@@ -179,19 +184,6 @@ def save(self):
179184
for _fh in handles:
180185
_fh.close()
181186

182-
# GH 17778 handles zip compression for byte strings separately.
183-
# if path is not None:
184-
# buf = f.getvalue()
185-
# f, handles = _get_handle(path, self.mode,
186-
# encoding=encoding,
187-
# compression=self.compression)
188-
# f.write(buf)
189-
#
190-
# if not py2zip:
191-
# f.close()
192-
# for _fh in handles:
193-
# _fh.close()
194-
195187
def _save_header(self):
196188

197189
writer = self.writer

0 commit comments

Comments
 (0)