@@ -1633,8 +1633,12 @@ def _testit(op):
1633
1633
result = op (grouped )['C' ]
1634
1634
assert_series_equal (result , exp )
1635
1635
1636
+ _testit (lambda x : x .count ())
1636
1637
_testit (lambda x : x .sum ())
1638
+ _testit (lambda x : x .std ())
1639
+ _testit (lambda x : x .var ())
1637
1640
_testit (lambda x : x .mean ())
1641
+ _testit (lambda x : x .median ())
1638
1642
_testit (lambda x : x .prod ())
1639
1643
_testit (lambda x : x .min ())
1640
1644
_testit (lambda x : x .max ())
@@ -4166,7 +4170,7 @@ def test_tab_completion(self):
4166
4170
'agg' ,'aggregate' ,'apply' ,'boxplot' ,'filter' ,'first' ,'get_group' ,
4167
4171
'groups' ,'hist' ,'indices' ,'last' ,'max' ,'mean' ,'median' ,
4168
4172
'min' ,'name' ,'ngroups' ,'nth' ,'ohlc' ,'plot' , 'prod' ,
4169
- 'size' ,'std' ,'sum' ,'transform' ,'var' , 'count' , 'head' , 'describe' ,
4173
+ 'size' , 'std' , 'sum' , 'transform' , 'var' , 'count' , 'head' , 'describe' ,
4170
4174
'cummax' , 'quantile' , 'rank' , 'cumprod' , 'tail' ,
4171
4175
'resample' , 'cummin' , 'fillna' , 'cumsum' , 'cumcount' ,
4172
4176
'all' , 'shift' , 'skew' , 'bfill' , 'irow' , 'ffill' ,
@@ -4306,6 +4310,55 @@ def __eq__(self, other):
4306
4310
name = 'grp' ))
4307
4311
tm .assert_frame_equal (result , expected )
4308
4312
4313
+ def test__cython_agg_general (self ):
4314
+ ops = [('mean' , np .mean ),
4315
+ ('median' , np .median ),
4316
+ ('var' , np .var ),
4317
+ ('add' , np .sum ),
4318
+ ('prod' , np .prod ),
4319
+ ('min' , np .min ),
4320
+ ('max' , np .max ),
4321
+ ('first' , lambda x : x .iloc [0 ]),
4322
+ ('last' , lambda x : x .iloc [- 1 ]),
4323
+ ('count' , np .size ),
4324
+ ]
4325
+ df = DataFrame (np .random .randn (1000 ))
4326
+ labels = np .random .randint (0 , 50 , size = 1000 ).astype (float )
4327
+
4328
+ for op , targop in ops :
4329
+ result = df .groupby (labels )._cython_agg_general (op )
4330
+ expected = df .groupby (labels ).agg (targop )
4331
+ try :
4332
+ tm .assert_frame_equal (result , expected )
4333
+ except BaseException as exc :
4334
+ exc .args += ('operation: %s' % op ,)
4335
+ raise
4336
+
4337
+ def test_ops_general (self ):
4338
+ ops = [('mean' , np .mean ),
4339
+ ('median' , np .median ),
4340
+ ('std' , np .std ),
4341
+ ('var' , np .var ),
4342
+ ('sum' , np .sum ),
4343
+ ('prod' , np .prod ),
4344
+ ('min' , np .min ),
4345
+ ('max' , np .max ),
4346
+ ('first' , lambda x : x .iloc [0 ]),
4347
+ ('last' , lambda x : x .iloc [- 1 ]),
4348
+ ('count' , np .size ),
4349
+ ]
4350
+ df = DataFrame (np .random .randn (1000 ))
4351
+ labels = np .random .randint (0 , 50 , size = 1000 ).astype (float )
4352
+
4353
+ for op , targop in ops :
4354
+ result = getattr (df .groupby (labels ), op )().astype (float )
4355
+ expected = df .groupby (labels ).agg (targop )
4356
+ try :
4357
+ tm .assert_frame_equal (result , expected )
4358
+ except BaseException as exc :
4359
+ exc .args += ('operation: %s' % op ,)
4360
+ raise
4361
+
4309
4362
4310
4363
def assert_fp_equal (a , b ):
4311
4364
assert (np .abs (a - b ) < 1e-12 ).all ()
0 commit comments