@@ -61,29 +61,33 @@ def test_string_io(self):
61
61
62
62
df = DataFrame (np .random .randn (10 ,2 ))
63
63
s = df .to_msgpack (None )
64
- result = read_msgpack (s .getvalue ())
64
+ result = read_msgpack (s )
65
+ tm .assert_frame_equal (result ,df )
66
+
67
+ s = df .to_msgpack ()
68
+ result = read_msgpack (s )
69
+ tm .assert_frame_equal (result ,df )
70
+
71
+ s = df .to_msgpack ()
72
+ result = read_msgpack (compat .BytesIO (s ))
65
73
tm .assert_frame_equal (result ,df )
66
74
67
75
s = to_msgpack (None ,df )
68
- result = read_msgpack (s . getvalue () )
76
+ result = read_msgpack (s )
69
77
tm .assert_frame_equal (result , df )
70
78
71
79
with ensure_clean (self .path ) as p :
72
80
73
- s = df .to_msgpack (None )
81
+ s = df .to_msgpack ()
74
82
fh = open (p ,'wb' )
75
- fh .write (s . getvalue () )
83
+ fh .write (s )
76
84
fh .close ()
77
85
result = read_msgpack (p )
78
86
tm .assert_frame_equal (result , df )
79
87
80
88
def test_iterator_with_string_io (self ):
81
89
82
90
dfs = [ DataFrame (np .random .randn (10 ,2 )) for i in range (5 ) ]
83
- s = to_msgpack (None ,* dfs )
84
- for i , result in enumerate (read_msgpack (s .getvalue (),iterator = True )):
85
- tm .assert_frame_equal (result ,dfs [i ])
86
-
87
91
s = to_msgpack (None ,* dfs )
88
92
for i , result in enumerate (read_msgpack (s ,iterator = True )):
89
93
tm .assert_frame_equal (result ,dfs [i ])
@@ -98,7 +102,7 @@ def test_numpy_scalar_float(self):
98
102
def test_numpy_scalar_complex (self ):
99
103
x = np .complex64 (np .random .rand () + 1j * np .random .rand ())
100
104
x_rec = self .encode_decode (x )
101
- tm . assert_almost_equal ( x , x_rec )
105
+ self . assert_ ( np . allclose ( x , x_rec ) )
102
106
103
107
def test_scalar_float (self ):
104
108
x = np .random .rand ()
@@ -108,10 +112,9 @@ def test_scalar_float(self):
108
112
def test_scalar_complex (self ):
109
113
x = np .random .rand () + 1j * np .random .rand ()
110
114
x_rec = self .encode_decode (x )
111
- tm . assert_almost_equal ( x , x_rec )
115
+ self . assert_ ( np . allclose ( x , x_rec ) )
112
116
113
117
def test_list_numpy_float (self ):
114
- raise nose .SkipTest ('buggy test' )
115
118
x = [np .float32 (np .random .rand ()) for i in range (5 )]
116
119
x_rec = self .encode_decode (x )
117
120
tm .assert_almost_equal (x ,x_rec )
@@ -120,13 +123,11 @@ def test_list_numpy_float_complex(self):
120
123
if not hasattr (np , 'complex128' ):
121
124
raise nose .SkipTest ('numpy cant handle complex128' )
122
125
123
- # buggy test
124
- raise nose .SkipTest ('buggy test' )
125
126
x = [np .float32 (np .random .rand ()) for i in range (5 )] + \
126
127
[np .complex128 (np .random .rand () + 1j * np .random .rand ())
127
128
for i in range (5 )]
128
129
x_rec = self .encode_decode (x )
129
- tm . assert_almost_equal ( x , x_rec )
130
+ self . assert_ ( np . allclose ( x , x_rec ) )
130
131
131
132
def test_list_float (self ):
132
133
x = [np .random .rand () for i in range (5 )]
@@ -137,7 +138,7 @@ def test_list_float_complex(self):
137
138
x = [np .random .rand () for i in range (5 )] + \
138
139
[(np .random .rand () + 1j * np .random .rand ()) for i in range (5 )]
139
140
x_rec = self .encode_decode (x )
140
- tm . assert_almost_equal ( x , x_rec )
141
+ self . assert_ ( np . allclose ( x , x_rec ) )
141
142
142
143
def test_dict_float (self ):
143
144
x = {'foo' : 1.0 , 'bar' : 2.0 }
@@ -147,7 +148,8 @@ def test_dict_float(self):
147
148
def test_dict_complex (self ):
148
149
x = {'foo' : 1.0 + 1.0j , 'bar' : 2.0 + 2.0j }
149
150
x_rec = self .encode_decode (x )
150
- tm .assert_almost_equal (x ,x_rec )
151
+ self .assert_ (all (map (lambda x , y : x == y , x .values (), x_rec .values ())) and
152
+ all (map (lambda x , y : type (x ) == type (y ), x .values (), x_rec .values ())))
151
153
152
154
def test_dict_numpy_float (self ):
153
155
x = {'foo' : np .float32 (1.0 ), 'bar' : np .float32 (2.0 )}
@@ -158,7 +160,9 @@ def test_dict_numpy_complex(self):
158
160
x = {'foo' : np .complex128 (
159
161
1.0 + 1.0j ), 'bar' : np .complex128 (2.0 + 2.0j )}
160
162
x_rec = self .encode_decode (x )
161
- tm .assert_almost_equal (x ,x_rec )
163
+ self .assert_ (all (map (lambda x , y : x == y , x .values (), x_rec .values ())) and
164
+ all (map (lambda x , y : type (x ) == type (y ), x .values (), x_rec .values ())))
165
+
162
166
163
167
def test_numpy_array_float (self ):
164
168
@@ -173,7 +177,8 @@ def test_numpy_array_float(self):
173
177
def test_numpy_array_complex (self ):
174
178
x = (np .random .rand (5 ) + 1j * np .random .rand (5 )).astype (np .complex128 )
175
179
x_rec = self .encode_decode (x )
176
- tm .assert_almost_equal (x ,x_rec )
180
+ self .assert_ (all (map (lambda x , y : x == y , x , x_rec )) and
181
+ x .dtype == x_rec .dtype )
177
182
178
183
def test_list_mixed (self ):
179
184
x = [1.0 , np .float32 (3.5 ), np .complex128 (4.25 ), u ('foo' )]
@@ -235,6 +240,16 @@ def test_basic_index(self):
235
240
i_rec = self .encode_decode (i )
236
241
self .assert_ (i .equals (i_rec ))
237
242
243
+ # datetime with no freq (GH5506)
244
+ i = Index ([Timestamp ('20130101' ),Timestamp ('20130103' )])
245
+ i_rec = self .encode_decode (i )
246
+ self .assert_ (i .equals (i_rec ))
247
+
248
+ # datetime with timezone
249
+ i = Index ([Timestamp ('20130101 9:00:00' ),Timestamp ('20130103 11:00:00' )]).tz_localize ('US/Eastern' )
250
+ i_rec = self .encode_decode (i )
251
+ self .assert_ (i .equals (i_rec ))
252
+
238
253
def test_multi_index (self ):
239
254
240
255
for s , i in self .mi .items ():
0 commit comments