@@ -533,26 +533,10 @@ def f():
533
533
self .frame .transform (['max' , 'sqrt' ])
534
534
self .assertRaises (ValueError , f )
535
535
536
- def test_agg_todo (self ):
537
- # if we have a transforming function & a reducer
538
- # we have to resolve
539
- # TODO
540
- # result = self.frame.apply([np.sqrt, np.mean])
541
-
542
- # TODO
543
- # difference in apply / agg semantics when passing a
544
- # row-wise aggregator
545
- pass
546
-
547
- def test_broken (self ):
548
- # TODO
549
- # df = pd.DataFrame({'A': range(5), 'B': 5})
550
- # result = df.agg({'A':['abs', 'sum'], 'B':['mean','max']})
551
- # expected = DataFrame({'A': [0, 4], 'B': [5, 5]},
552
- # columns=['A', 'B'],
553
- # index=['min', 'max'])
554
- # tm.assert_frame_equal(result, expected)
555
- pass
536
+ df = pd .DataFrame ({'A' : range (5 ), 'B' : 5 })
537
+ def f ():
538
+ with np .errstate (all = 'ignore' ):
539
+ df .agg ({'A' :['abs' , 'sum' ], 'B' :['mean' ,'max' ]})
556
540
557
541
def test_demo (self ):
558
542
# demonstration tests
@@ -604,3 +588,31 @@ def test_agg_reduce(self):
604
588
self .frame .B .max ()],
605
589
index = ['sum' , 'max' ])})
606
590
assert_frame_equal (result .reindex_like (expected ), expected )
591
+
592
+ def test_nuiscance_columns (self ):
593
+
594
+ # GH 15015
595
+ df = DataFrame ({'A' : [1 , 2 , 3 ],
596
+ 'B' : [1. , 2. , 3. ],
597
+ 'C' : ['foo' , 'bar' , 'baz' ],
598
+ 'D' : pd .date_range ('20130101' , periods = 3 )})
599
+
600
+ result = df .agg ('min' )
601
+ expected = Series ([1 , 1. , 'bar' , pd .Timestamp ('20130101' )],
602
+ index = df .columns )
603
+ assert_series_equal (result , expected )
604
+
605
+ result = df .agg (['min' ])
606
+ expected = DataFrame ([[1 , 1. , 'bar' , pd .Timestamp ('20130101' )]],
607
+ index = ['min' ], columns = df .columns )
608
+ assert_frame_equal (result , expected )
609
+
610
+ result = df .agg ('sum' )
611
+ expected = Series ([6 , 6. , 'foobarbaz' ],
612
+ index = ['A' , 'B' , 'C' ])
613
+ assert_series_equal (result , expected )
614
+
615
+ result = df .agg (['sum' ])
616
+ expected = DataFrame ([[6 , 6. , 'foobarbaz' ]],
617
+ index = ['sum' ], columns = ['A' , 'B' , 'C' ])
618
+ assert_frame_equal (result , expected )
0 commit comments