@@ -402,6 +402,16 @@ class Size(SingleAggregation):
402
402
groupby_aggregate = M .sum
403
403
404
404
405
+ class IdxMin (SingleAggregation ):
406
+ groupby_chunk = M .idxmin
407
+ groupby_aggregate = M .first
408
+
409
+
410
+ class IdxMax (IdxMin ):
411
+ groupby_chunk = M .idxmax
412
+ groupby_aggregate = M .first
413
+
414
+
405
415
class ValueCounts (SingleAggregation ):
406
416
groupby_chunk = staticmethod (_value_counts )
407
417
groupby_aggregate = staticmethod (_value_counts_aggregate )
@@ -1043,7 +1053,7 @@ def __init__(
1043
1053
1044
1054
def _numeric_only_kwargs (self , numeric_only ):
1045
1055
kwargs = {"numeric_only" : numeric_only }
1046
- return {"chunk_kwargs" : kwargs , "aggregate_kwargs" : kwargs }
1056
+ return {"chunk_kwargs" : kwargs . copy () , "aggregate_kwargs" : kwargs . copy () }
1047
1057
1048
1058
def _single_agg (
1049
1059
self ,
@@ -1183,6 +1193,26 @@ def size(self, **kwargs):
1183
1193
def value_counts (self , ** kwargs ):
1184
1194
return self ._single_agg (ValueCounts , ** kwargs )
1185
1195
1196
+ def idxmin (
1197
+ self , split_every = None , split_out = 1 , skipna = True , numeric_only = False , ** kwargs
1198
+ ):
1199
+ # TODO: Add shuffle and remove kwargs
1200
+ numeric_kwargs = self ._numeric_only_kwargs (numeric_only )
1201
+ numeric_kwargs ["chunk_kwargs" ]["skipna" ] = skipna
1202
+ return self ._single_agg (
1203
+ IdxMin , split_every = split_every , split_out = split_out , ** numeric_kwargs
1204
+ )
1205
+
1206
+ def idxmax (
1207
+ self , split_every = None , split_out = 1 , skipna = True , numeric_only = False , ** kwargs
1208
+ ):
1209
+ # TODO: Add shuffle and remove kwargs
1210
+ numeric_kwargs = self ._numeric_only_kwargs (numeric_only )
1211
+ numeric_kwargs ["chunk_kwargs" ]["skipna" ] = skipna
1212
+ return self ._single_agg (
1213
+ IdxMax , split_every = split_every , split_out = split_out , ** numeric_kwargs
1214
+ )
1215
+
1186
1216
def head (self , n = 5 , split_every = None , split_out = 1 ):
1187
1217
chunk_kwargs = {"n" : n }
1188
1218
aggregate_kwargs = {
@@ -1431,6 +1461,28 @@ def aggregate(self, arg=None, split_every=8, split_out=1, **kwargs):
1431
1461
1432
1462
agg = aggregate
1433
1463
1464
+ def idxmin (
1465
+ self , split_every = None , split_out = 1 , skipna = True , numeric_only = False , ** kwargs
1466
+ ):
1467
+ # pandas doesn't support numeric_only here, which is odd
1468
+ return self ._single_agg (
1469
+ IdxMin ,
1470
+ split_every = None ,
1471
+ split_out = split_out ,
1472
+ chunk_kwargs = dict (skipna = skipna ),
1473
+ )
1474
+
1475
+ def idxmax (
1476
+ self , split_every = None , split_out = 1 , skipna = True , numeric_only = False , ** kwargs
1477
+ ):
1478
+ # pandas doesn't support numeric_only here, which is odd
1479
+ return self ._single_agg (
1480
+ IdxMax ,
1481
+ split_every = split_every ,
1482
+ split_out = split_out ,
1483
+ chunk_kwargs = dict (skipna = skipna ),
1484
+ )
1485
+
1434
1486
def nunique (self , split_every = None , split_out = True ):
1435
1487
slice = self ._slice or self .obj .name
1436
1488
return new_collection (
0 commit comments