Skip to content

Commit ab7a7b7

Browse files
committed
enable zip compression for Python 2 by avoid pickle.dump
1 parent fd44980 commit ab7a7b7

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

pandas/io/common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
366366
elif compression == 'zip':
367367
zf = BytesZipFile(path_or_buf, mode)
368368
if zf.mode == 'w':
369-
if compat.PY3:
370-
f = zf
371-
elif compat.PY2:
372-
raise NotImplementedError('Writing zip compression is not'
373-
' supported in Python 2.')
369+
f = zf
374370
elif zf.mode == 'r':
375371
zip_names = zf.namelist()
376372
if len(zip_names) == 1:

pandas/io/pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def to_pickle(obj, path, compression='infer', protocol=pkl.HIGHEST_PROTOCOL):
7474
if protocol < 0:
7575
protocol = pkl.HIGHEST_PROTOCOL
7676
try:
77-
pkl.dump(obj, f, protocol=protocol)
77+
f.write(pkl.dumps(obj, protocol=protocol))
7878
finally:
7979
for _f in fh:
8080
_f.close()

0 commit comments

Comments
 (0)