3
3
from datetime import datetime , timedelta
4
4
from functools import partial
5
5
6
- from pandas .compat import range , lrange , zip , product
6
+ from pandas .compat import range , lrange , zip , product , OrderedDict
7
7
import numpy as np
8
8
9
9
from pandas import (Series , DataFrame , Panel , Index , isnull ,
31
31
bday = BDay ()
32
32
33
33
34
- def compare_frame_like (result , expected ):
35
- # if we are using dicts, the orderings is not guaranteed
36
- assert_frame_equal (result .reindex_like (expected ), expected )
37
-
38
-
39
34
class TestResampleAPI (tm .TestCase ):
40
35
_multiprocess_can_split_ = True
41
36
@@ -211,7 +206,7 @@ def test_downsample_but_actually_upsampling(self):
211
206
212
207
# this is reindex / asfreq
213
208
rng = pd .date_range ('1/1/2012' , periods = 100 , freq = 'S' )
214
- ts = pd .Series (np .arange (len (rng )), index = rng )
209
+ ts = pd .Series (np .arange (len (rng ), dtype = 'int64' ), index = rng )
215
210
result = ts .resample ('20s' ).asfreq ()
216
211
expected = Series ([0 , 20 , 40 , 60 , 80 ],
217
212
index = pd .date_range ('2012-01-01 00:00:00' ,
@@ -271,7 +266,7 @@ def test_agg(self):
271
266
for t in [r , g ]:
272
267
result = t .aggregate ({'A' : np .mean ,
273
268
'B' : np .std })
274
- compare_frame_like (result , expected )
269
+ assert_frame_equal (result , expected , check_like = True )
275
270
276
271
expected = pd .concat ([a_mean , a_std ], axis = 1 )
277
272
expected .columns = pd .MultiIndex .from_tuples ([('A' , 'mean' ),
@@ -291,7 +286,7 @@ def test_agg(self):
291
286
('A' , 'sum' )])
292
287
for t in [r , g ]:
293
288
result = t .aggregate ({'A' : {'mean' : 'mean' , 'sum' : 'sum' }})
294
- compare_frame_like (result , expected )
289
+ assert_frame_equal (result , expected , check_like = True )
295
290
296
291
expected = pd .concat ([a_mean , a_sum , b_mean , b_sum ], axis = 1 )
297
292
expected .columns = pd .MultiIndex .from_tuples ([('A' , 'mean' ),
@@ -301,7 +296,7 @@ def test_agg(self):
301
296
for t in [r , g ]:
302
297
result = t .aggregate ({'A' : {'mean' : 'mean' , 'sum' : 'sum' },
303
298
'B' : {'mean2' : 'mean' , 'sum2' : 'sum' }})
304
- compare_frame_like (result , expected )
299
+ assert_frame_equal (result , expected , check_like = True )
305
300
306
301
expected = pd .concat ([a_mean , a_std , b_mean , b_std ], axis = 1 )
307
302
expected .columns = pd .MultiIndex .from_tuples ([('A' , 'mean' ),
@@ -311,7 +306,7 @@ def test_agg(self):
311
306
for t in [r , g ]:
312
307
result = t .aggregate ({'A' : ['mean' , 'std' ],
313
308
'B' : ['mean' , 'std' ]})
314
- compare_frame_like (result , expected )
309
+ assert_frame_equal (result , expected , check_like = True )
315
310
316
311
expected = pd .concat ([a_mean , a_sum , b_mean , b_sum ], axis = 1 )
317
312
expected .columns = pd .MultiIndex .from_tuples ([('r1' , 'A' , 'mean' ),
@@ -338,19 +333,39 @@ def test_agg_misc(self):
338
333
'B' : lambda x : np .std (x , ddof = 1 )})
339
334
rcustom = t ['B' ].apply (lambda x : np .std (x , ddof = 1 ))
340
335
expected = pd .concat ([r ['A' ].sum (), rcustom ], axis = 1 )
341
- compare_frame_like (result , expected )
336
+ assert_frame_equal (result , expected , check_like = True )
342
337
343
338
# misc
339
+ expected = pd .concat ([t ['A' ].sum (),
340
+ t ['B' ].sum (),
341
+ t ['A' ].mean (),
342
+ t ['B' ].mean ()],
343
+ axis = 1 )
344
+ expected .columns = pd .MultiIndex .from_tuples ([('result1' , 'A' ),
345
+ ('result1' , 'B' ),
346
+ ('result2' , 'A' ),
347
+ ('result2' , 'B' )])
344
348
for t in [r , g ]:
345
- t [['A' , 'B' ]].agg ({'result1' : np .sum , 'result2' : np .mean })
349
+ result = t [['A' , 'B' ]].agg (OrderedDict ([('result1' , np .sum ),
350
+ ('result2' , np .mean )]))
351
+ assert_frame_equal (result , expected , check_like = True )
346
352
347
353
for t in [r , g ]:
348
354
t .agg ({'A' : ['sum' , 'std' ], 'B' : ['mean' , 'std' ]})
349
355
356
+ # what should this produce??????
357
+ import pdb ; pdb .set_trace ()
350
358
for t in [r , g ]:
351
359
t [['A' , 'B' ]].agg ({'A' : ['sum' , 'std' ],
352
360
'B' : ['mean' , 'std' ]})
353
361
362
+ # errors
363
+ for t in [r , g ]:
364
+ r [['A' ]].agg ({'A' : ['sum' , 'std' ], 'B' : ['mean' , 'std' ]})
365
+
366
+ for t in [r , g ]:
367
+ r ['A' ].agg ({'A' : ['sum' , 'std' ], 'B' : ['mean' , 'std' ]})
368
+
354
369
355
370
class TestResample (tm .TestCase ):
356
371
_multiprocess_can_split_ = True
@@ -515,7 +530,7 @@ def test_resample_with_timedeltas(self):
515
530
516
531
def test_resample_single_period_timedelta (self ):
517
532
518
- s = Series (range (5 ), index = pd .timedelta_range (
533
+ s = Series (list ( range (5 ) ), index = pd .timedelta_range (
519
534
'1 day' , freq = 's' , periods = 5 ))
520
535
result = s .resample ('2s' ).sum ()
521
536
expected = Series ([1 , 5 , 4 ], index = pd .timedelta_range (
0 commit comments