Skip to content

Commit f418a0e

Browse files
committed
Merge pull request #4063 from cpcloud/tox-pkl-import-fix
TST/BUG: fix 2to3 import rewrite of import pickle
2 parents 5abe1a2 + 858da94 commit f418a0e

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ pandas 0.12
294294
- ``Series.hist`` will now take the figure from the current environment if
295295
one is not passed
296296
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
297+
- Fixed running of ``tox`` under python3 where the pickle import was getting
298+
rewritten in an incompatible way (:issue:`4062`, :issue:`4063`)
297299

298300

299301
pandas 0.11.0

doc/source/v0.12.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ Bug Fixes
437437
- ``Series.hist`` will now take the figure from the current environment if
438438
one is not passed
439439
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
440+
- Fixed running of ``tox`` under python3 where the pickle import was getting
441+
rewritten in an incompatible way (:issue:`4062`, :issue:`4063`)
440442

441443
See the :ref:`full release notes
442444
<release>` or issue tracker

pandas/io/pickle.py

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# XXX: HACK for NumPy 1.5.1 to suppress warnings
2-
try:
3-
import cPickle as pickle
4-
except ImportError: # pragma: no cover
5-
import pickle
1+
import cPickle as pkl
2+
63

74
def to_pickle(obj, path):
85
"""
@@ -14,11 +11,9 @@ def to_pickle(obj, path):
1411
path : string
1512
File path
1613
"""
17-
f = open(path, 'wb')
18-
try:
19-
pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL)
20-
finally:
21-
f.close()
14+
with open(path, 'wb') as f:
15+
pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL)
16+
2217

2318
def read_pickle(path):
2419
"""
@@ -38,11 +33,11 @@ def read_pickle(path):
3833
unpickled : type of object stored in file
3934
"""
4035
try:
41-
with open(path,'rb') as fh:
42-
return pickle.load(fh)
36+
with open(path, 'rb') as fh:
37+
return pkl.load(fh)
4338
except:
44-
from pandas.util import py3compat
45-
if not py3compat.PY3:
46-
raise
47-
with open(path,'rb') as fh:
48-
return pickle.load(fh, encoding='latin1')
39+
from pandas.util.py3compat import PY3
40+
if PY3:
41+
with open(path, 'rb') as fh:
42+
return pkl.load(fh, encoding='latin1')
43+
raise

tox_prll.sh

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ for e in $ENVS; do
2525
echo "[launching tox for $e]"
2626
tox -c "$TOX_INI_PAR" -e "$e" &
2727
done
28+
wait

0 commit comments

Comments
 (0)