@@ -319,12 +319,9 @@ def get_group_levels(self):
319
319
"min" : "group_min" ,
320
320
"max" : "group_max" ,
321
321
"mean" : "group_mean" ,
322
- "median" : { "name" : " group_median"} ,
322
+ "median" : " group_median" ,
323
323
"var" : "group_var" ,
324
- "first" : {
325
- "name" : "group_nth" ,
326
- "f" : lambda func , a , b , c , d , e : func (a , b , c , d , 1 , - 1 ),
327
- },
324
+ "first" : "group_nth" ,
328
325
"last" : "group_last" ,
329
326
"ohlc" : "group_ohlc" ,
330
327
},
@@ -333,19 +330,7 @@ def get_group_levels(self):
333
330
"cumsum" : "group_cumsum" ,
334
331
"cummin" : "group_cummin" ,
335
332
"cummax" : "group_cummax" ,
336
- "rank" : {
337
- "name" : "group_rank" ,
338
- "f" : lambda func , a , b , c , d , e , ** kwargs : func (
339
- a ,
340
- b ,
341
- c ,
342
- e ,
343
- kwargs .get ("ties_method" , "average" ),
344
- kwargs .get ("ascending" , True ),
345
- kwargs .get ("pct" , False ),
346
- kwargs .get ("na_option" , "keep" ),
347
- ),
348
- },
333
+ "rank" : "group_rank" ,
349
334
},
350
335
}
351
336
@@ -391,21 +376,7 @@ def get_func(fname):
391
376
392
377
ftype = self ._cython_functions [kind ][how ]
393
378
394
- if isinstance (ftype , dict ):
395
- func = afunc = get_func (ftype ["name" ])
396
-
397
- # a sub-function
398
- f = ftype .get ("f" )
399
- if f is not None :
400
-
401
- def wrapper (* args , ** kwargs ):
402
- return f (afunc , * args , ** kwargs )
403
-
404
- # need to curry our sub-function
405
- func = wrapper
406
-
407
- else :
408
- func = get_func (ftype )
379
+ func = get_func (ftype )
409
380
410
381
if func is None :
411
382
raise NotImplementedError (
@@ -517,14 +488,7 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
517
488
)
518
489
counts = np .zeros (self .ngroups , dtype = np .int64 )
519
490
result = self ._aggregate (
520
- result ,
521
- counts ,
522
- values ,
523
- labels ,
524
- func ,
525
- is_numeric ,
526
- is_datetimelike ,
527
- min_count ,
491
+ result , counts , values , labels , func , is_datetimelike , min_count
528
492
)
529
493
elif kind == "transform" :
530
494
result = _maybe_fill (
@@ -533,7 +497,7 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
533
497
534
498
# TODO: min_count
535
499
result = self ._transform (
536
- result , values , labels , func , is_numeric , is_datetimelike , ** kwargs
500
+ result , values , labels , func , is_datetimelike , ** kwargs
537
501
)
538
502
539
503
if is_integer_dtype (result ) and not is_datetimelike :
@@ -574,33 +538,22 @@ def transform(self, values, how, axis=0, **kwargs):
574
538
return self ._cython_operation ("transform" , values , how , axis , ** kwargs )
575
539
576
540
def _aggregate (
577
- self ,
578
- result ,
579
- counts ,
580
- values ,
581
- comp_ids ,
582
- agg_func ,
583
- is_numeric ,
584
- is_datetimelike ,
585
- min_count = - 1 ,
541
+ self , result , counts , values , comp_ids , agg_func , is_datetimelike , min_count = - 1
586
542
):
587
543
if values .ndim > 2 :
588
544
# punting for now
589
545
raise NotImplementedError ("number of dimensions is currently limited to 2" )
546
+ elif agg_func is libgroupby .group_nth :
547
+ # different signature from the others
548
+ # TODO: should we be using min_count instead of hard-coding it?
549
+ agg_func (result , counts , values , comp_ids , rank = 1 , min_count = - 1 )
590
550
else :
591
551
agg_func (result , counts , values , comp_ids , min_count )
592
552
593
553
return result
594
554
595
555
def _transform (
596
- self ,
597
- result ,
598
- values ,
599
- comp_ids ,
600
- transform_func ,
601
- is_numeric ,
602
- is_datetimelike ,
603
- ** kwargs
556
+ self , result , values , comp_ids , transform_func , is_datetimelike , ** kwargs
604
557
):
605
558
606
559
comp_ids , _ , ngroups = self .group_info
0 commit comments