Skip to content

TST/BUG: fix 2to3 import rewrite of import pickle #4063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ pandas 0.12
- ``Series.hist`` will now take the figure from the current environment if
one is not passed
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
- Fixed running of ``tox`` under python3 where the pickle import was getting
rewritten in an incompatible way (:issue:`4062`, :issue:`4063`)


pandas 0.11.0
Expand Down
2 changes: 2 additions & 0 deletions doc/source/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ Bug Fixes
- ``Series.hist`` will now take the figure from the current environment if
one is not passed
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
- Fixed running of ``tox`` under python3 where the pickle import was getting
rewritten in an incompatible way (:issue:`4062`, :issue:`4063`)

See the :ref:`full release notes
<release>` or issue tracker
Expand Down
29 changes: 12 additions & 17 deletions pandas/io/pickle.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# XXX: HACK for NumPy 1.5.1 to suppress warnings
try:
import cPickle as pickle
except ImportError: # pragma: no cover
import pickle
import cPickle as pkl


def to_pickle(obj, path):
"""
Expand All @@ -14,11 +11,9 @@ def to_pickle(obj, path):
path : string
File path
"""
f = open(path, 'wb')
try:
pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL)
finally:
f.close()
with open(path, 'wb') as f:
pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL)


def read_pickle(path):
"""
Expand All @@ -38,11 +33,11 @@ def read_pickle(path):
unpickled : type of object stored in file
"""
try:
with open(path,'rb') as fh:
return pickle.load(fh)
with open(path, 'rb') as fh:
return pkl.load(fh)
except:
from pandas.util import py3compat
if not py3compat.PY3:
raise
with open(path,'rb') as fh:
return pickle.load(fh, encoding='latin1')
from pandas.util.py3compat import PY3
if PY3:
with open(path, 'rb') as fh:
return pkl.load(fh, encoding='latin1')
raise
1 change: 1 addition & 0 deletions tox_prll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ for e in $ENVS; do
echo "[launching tox for $e]"
tox -c "$TOX_INI_PAR" -e "$e" &
done
wait