Skip to content

Fixes for tests on Python 3 #685

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 9 additions & 4 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""
Misc tools for implementing data structures
"""
import cPickle
try:
import cPickle as pickle
except ImportError:
import pickle

try:
from io import BytesIO
except ImportError: # pragma: no cover
Expand All @@ -16,6 +20,7 @@
import math

import pandas._tseries as lib
from pandas.util import py3compat

# XXX: HACK for NumPy 1.5.1 to suppress warnings
try:
Expand Down Expand Up @@ -788,7 +793,7 @@ def save(obj, path):
"""
f = open(path, 'wb')
try:
cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL)
finally:
f.close()

Expand All @@ -809,13 +814,13 @@ def load(path):
"""
f = open(path, 'rb')
try:
return cPickle.load(f)
return pickle.load(f)
finally:
f.close()


def console_encode(value):
if not isinstance(value, unicode):
if py3compat.PY3 or not isinstance(value, unicode):
return value

try:
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
assert_frame_equal)

import pandas.util.testing as tm
from pandas.util import py3compat
import pandas._tseries as lib

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1844,7 +1845,10 @@ def test_to_string_unicode_two(self):
def test_to_string_with_formatters_unicode(self):
df = DataFrame({u'c/\u03c3':[1,2,3]})
result = df.to_string(formatters={u'c/\u03c3': lambda x: '%s' % x})
assert(result in (' c/\xcf\x83\n0 1 \n1 2 \n2 3 ',
if py3compat.PY3:
self.assertEqual(result, u' c/\u03c3\n0 1 \n1 2 \n2 3 ')
else:
assert(result in (' c/\xcf\x83\n0 1 \n1 2 \n2 3 ',
' c/?\n0 1 \n1 2 \n2 3 ' ))

def test_head_tail(self):
Expand Down