File tree 2 files changed +17
-8
lines changed
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
Misc tools for implementing data structures
3
3
"""
4
- import cPickle
4
+ try :
5
+ import cPickle as pickle
6
+ except ImportError :
7
+ import pickle
8
+
5
9
try :
6
10
from io import BytesIO
7
11
except ImportError : # pragma: no cover
16
20
import math
17
21
18
22
import pandas ._tseries as lib
23
+ from pandas .util import py3compat
19
24
20
25
# XXX: HACK for NumPy 1.5.1 to suppress warnings
21
26
try :
@@ -788,7 +793,7 @@ def save(obj, path):
788
793
"""
789
794
f = open (path , 'wb' )
790
795
try :
791
- cPickle .dump (obj , f , protocol = cPickle .HIGHEST_PROTOCOL )
796
+ pickle .dump (obj , f , protocol = pickle .HIGHEST_PROTOCOL )
792
797
finally :
793
798
f .close ()
794
799
@@ -809,13 +814,13 @@ def load(path):
809
814
"""
810
815
f = open (path , 'rb' )
811
816
try :
812
- return cPickle .load (f )
817
+ return pickle .load (f )
813
818
finally :
814
819
f .close ()
815
820
816
821
817
822
def console_encode (value ):
818
- if not isinstance (value , unicode ):
823
+ if py3compat . PY3 or not isinstance (value , unicode ):
819
824
return value
820
825
821
826
try :
Original file line number Diff line number Diff line change 24
24
assert_frame_equal )
25
25
26
26
import pandas .util .testing as tm
27
+ from pandas .util import py3compat
27
28
import pandas ._tseries as lib
28
29
29
30
#-------------------------------------------------------------------------------
@@ -1844,10 +1845,13 @@ def test_to_string_unicode_two(self):
1844
1845
def test_to_string_with_formatters_unicode (self ):
1845
1846
df = DataFrame ({u'c/\u03c3 ' :[1 ,2 ,3 ]})
1846
1847
result = df .to_string (formatters = {u'c/\u03c3 ' : lambda x : '%s' % x })
1847
- assert (result in
1848
- (' c/\xcf \x83 \n 0 1 \n 1 2 \n 2 3 ' ,
1849
- u' c/\u03c3 \n 0 1 \n 1 2 \n 2 3 ' .encode ('cp437' , 'ignore' ),
1850
- ' c/?\n 0 1 \n 1 2 \n 2 3 ' ))
1848
+ cp437 = u' c/\u03c3 \n 0 1 \n 1 2 \n 2 3 ' .encode ('cp437' , 'ignore' )
1849
+ if py3compat .PY3 :
1850
+ self .assertEqual (result , u' c/\u03c3 \n 0 1 \n 1 2 \n 2 3 ' )
1851
+ else :
1852
+ assert (result in
1853
+ (' c/\xcf \x83 \n 0 1 \n 1 2 \n 2 3 ' , cp437 ,
1854
+ ' c/?\n 0 1 \n 1 2 \n 2 3 ' ))
1851
1855
1852
1856
def test_head_tail (self ):
1853
1857
assert_frame_equal (self .frame .head (), self .frame [:5 ])
You can’t perform that action at this time.
0 commit comments