@@ -512,12 +512,9 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
512512 elif func not in base .transform_kernel_allowlist :
513513 msg = f"'{ func } ' is not a valid function name for transform(name)"
514514 raise ValueError (msg )
515- elif func in base .cythonized_kernels :
515+ elif func in base .cythonized_kernels or func in base . transformation_kernels :
516516 # cythonized transform or canned "agg+broadcast"
517517 return getattr (self , func )(* args , ** kwargs )
518- elif func in base .transformation_kernels :
519- return getattr (self , func )(* args , ** kwargs )
520-
521518 # If func is a reduction, we need to broadcast the
522519 # result to the whole group. Compute func result
523520 # and deal with possible broadcasting below.
@@ -1111,8 +1108,7 @@ def blk_func(bvalues: ArrayLike) -> ArrayLike:
11111108 # unwrap DataFrame to get array
11121109 result = result ._mgr .blocks [0 ].values
11131110
1114- res_values = cast_agg_result (result , bvalues , how )
1115- return res_values
1111+ return cast_agg_result (result , bvalues , how )
11161112
11171113 # TypeError -> we may have an exception in trying to aggregate
11181114 # continue and exclude the block
@@ -1368,12 +1364,9 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
13681364 elif func not in base .transform_kernel_allowlist :
13691365 msg = f"'{ func } ' is not a valid function name for transform(name)"
13701366 raise ValueError (msg )
1371- elif func in base .cythonized_kernels :
1367+ elif func in base .cythonized_kernels or func in base . transformation_kernels :
13721368 # cythonized transformation or canned "reduction+broadcast"
13731369 return getattr (self , func )(* args , ** kwargs )
1374- elif func in base .transformation_kernels :
1375- return getattr (self , func )(* args , ** kwargs )
1376-
13771370 # GH 30918
13781371 # Use _transform_fast only when we know func is an aggregation
13791372 if func in base .reduction_kernels :
@@ -1401,9 +1394,10 @@ def _transform_fast(self, result: DataFrame) -> DataFrame:
14011394 # by take operation
14021395 ids , _ , ngroup = self .grouper .group_info
14031396 result = result .reindex (self .grouper .result_index , copy = False )
1404- output = []
1405- for i , _ in enumerate (result .columns ):
1406- output .append (algorithms .take_1d (result .iloc [:, i ].values , ids ))
1397+ output = [
1398+ algorithms .take_1d (result .iloc [:, i ].values , ids )
1399+ for i , _ in enumerate (result .columns )
1400+ ]
14071401
14081402 return self .obj ._constructor ._from_arrays (
14091403 output , columns = result .columns , index = obj .index
@@ -1462,7 +1456,7 @@ def _transform_item_by_item(self, obj: DataFrame, wrapper) -> DataFrame:
14621456 else :
14631457 inds .append (i )
14641458
1465- if len ( output ) == 0 :
1459+ if not output :
14661460 raise TypeError ("Transform function invalid for data types" )
14671461
14681462 columns = obj .columns
0 commit comments