@@ -1509,23 +1509,19 @@ def count(self):
1509
1509
DataFrame
1510
1510
Count of values within each group.
1511
1511
"""
1512
- obj = self ._selected_obj
1513
-
1514
- def groupby_series (obj , col = None ):
1515
- return SeriesGroupBy (obj , selection = col , grouper = self .grouper ).count ()
1516
-
1517
- if isinstance (obj , Series ):
1518
- results = groupby_series (obj )
1519
- else :
1520
- from pandas .core .reshape .concat import concat
1512
+ output = OrderedDict ()
1521
1513
1522
- results = [groupby_series (obj [col ], col ) for col in obj .columns ]
1523
- results = concat (results , axis = 1 )
1524
- results .columns .names = obj .columns .names
1525
-
1526
- if not self .as_index :
1527
- results .index = ibase .default_index (len (results ))
1528
- return results
1514
+ # TODO: dispatch to _cython_agg_general instead of custom looping
1515
+ # TODO: refactor with series logic
1516
+ ids , _ , ngroups = self .grouper .group_info
1517
+ for name , obj in self ._iterate_slices ():
1518
+ mask = (ids != - 1 ) & ~ isna (obj )
1519
+ ids = ensure_platform_int (ids )
1520
+ minlength = ngroups or 0
1521
+ out = np .bincount (ids [mask ], minlength = minlength )
1522
+ output [name ] = out
1523
+
1524
+ return self ._wrap_aggregated_output (output )
1529
1525
1530
1526
def nunique (self , dropna = True ):
1531
1527
"""
0 commit comments