@@ -2776,8 +2776,7 @@ def _transform_fast(self, func):
2776
2776
func = getattr (self , func )
2777
2777
2778
2778
ids , _ , ngroup = self .grouper .group_info
2779
- counts = self .size ().fillna (0 ).values
2780
- cast = (counts == 0 ).any ()
2779
+ cast = self .size ().isnull ().any ()
2781
2780
out = algos .take_1d (func ().values , ids )
2782
2781
if cast :
2783
2782
out = self ._try_cast (out , self .obj )
@@ -3459,23 +3458,28 @@ def transform(self, func, *args, **kwargs):
3459
3458
if not result .columns .equals (obj .columns ):
3460
3459
return self ._transform_general (func , * args , ** kwargs )
3461
3460
3462
- # Fast transform path for aggregations
3461
+ return self . _transform_fast ( result , obj )
3463
3462
3463
+ def _transform_fast (self , result , obj ):
3464
+ """
3465
+ Fast transform path for aggregations
3466
+ """
3464
3467
# if there were groups with no observations (Categorical only?)
3465
3468
# try casting data to original dtype
3466
- counts = self .size ().fillna (0 ).values
3467
- cast = (counts == 0 ).any ()
3469
+ cast = self .size ().isnull ().any ()
3468
3470
3469
- # by column (could be by block?) reshape aggregated data to
3470
- # size of original frame by repeating obvservations with take
3471
+ # for each col, reshape to to size of original frame
3472
+ # by take operation
3471
3473
ids , _ , ngroup = self .grouper .group_info
3472
- out = {}
3473
- for col in result :
3474
- out [ col ] = algos .take_nd (result [ col ].values , ids )
3474
+ output = []
3475
+ for i , _ in enumerate ( result . columns ) :
3476
+ res = algos .take_1d (result . iloc [:, i ].values , ids )
3475
3477
if cast :
3476
- out [col ] = self ._try_cast (out [col ], obj [col ])
3478
+ res = self ._try_cast (res , obj .iloc [:, i ])
3479
+ output .append (res )
3477
3480
3478
- return DataFrame (out , columns = result .columns , index = obj .index )
3481
+ return DataFrame ._from_arrays (output , columns = result .columns ,
3482
+ index = obj .index )
3479
3483
3480
3484
def _define_paths (self , func , * args , ** kwargs ):
3481
3485
if isinstance (func , compat .string_types ):
0 commit comments