Skip to content

Commit e71b09d

Browse files
committed
BUG: reading py2 pickles in py3 ok now
1 parent 76b0c54 commit e71b09d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ pandas 0.11.0
293293
- fixed pretty priniting of sets (GH3294_)
294294
- Panel() and Panel.from_dict() now respects ordering when give OrderedDict (GH3303_)
295295
- DataFrame where with a datetimelike incorrectly selecting (GH3311_)
296+
- Ensure pickles created in py2 can be read in py3
296297

297298
.. _GH3294: https://github.com/pydata/pandas/issues/3294
298299
.. _GH622: https://github.com/pydata/pandas/issues/622

pandas/core/common.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1575,12 +1575,12 @@ def load(path):
15751575
-------
15761576
unpickled : type of object stored in file
15771577
"""
1578-
f = open(path, 'rb')
15791578
try:
1580-
return pickle.load(f)
1581-
finally:
1582-
f.close()
1583-
1579+
with open(path,'rb') as fh:
1580+
return pickle.load(fh)
1581+
except:
1582+
with open(path,'rb') as fh:
1583+
return pickle.load(fh, encoding='latin1')
15841584

15851585
class UTF8Recoder:
15861586
"""

pandas/io/tests/test_pickle.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ def setUp(self):
2222

2323
def compare(self, vf):
2424

25-
fh = open(vf,'rb')
26-
data = pickle.load(fh)
27-
fh.close()
25+
# py3 compat when reading py2 pickle
26+
try:
27+
with open(vf,'rb') as fh:
28+
data = pickle.load(fh)
29+
except:
30+
with open(vf,'rb') as fh:
31+
data = pickle.load(fh, encoding='latin1')
2832

2933
for typ, dv in data.items():
3034
for dt, result in dv.items():

0 commit comments

Comments
 (0)