@@ -512,12 +512,9 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
512
512
elif func not in base .transform_kernel_allowlist :
513
513
msg = f"'{ func } ' is not a valid function name for transform(name)"
514
514
raise ValueError (msg )
515
- elif func in base .cythonized_kernels :
515
+ elif func in base .cythonized_kernels or func in base . transformation_kernels :
516
516
# cythonized transform or canned "agg+broadcast"
517
517
return getattr (self , func )(* args , ** kwargs )
518
- elif func in base .transformation_kernels :
519
- return getattr (self , func )(* args , ** kwargs )
520
-
521
518
# If func is a reduction, we need to broadcast the
522
519
# result to the whole group. Compute func result
523
520
# and deal with possible broadcasting below.
@@ -1111,8 +1108,7 @@ def blk_func(bvalues: ArrayLike) -> ArrayLike:
1111
1108
# unwrap DataFrame to get array
1112
1109
result = result ._mgr .blocks [0 ].values
1113
1110
1114
- res_values = cast_agg_result (result , bvalues , how )
1115
- return res_values
1111
+ return cast_agg_result (result , bvalues , how )
1116
1112
1117
1113
# TypeError -> we may have an exception in trying to aggregate
1118
1114
# continue and exclude the block
@@ -1368,12 +1364,9 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
1368
1364
elif func not in base .transform_kernel_allowlist :
1369
1365
msg = f"'{ func } ' is not a valid function name for transform(name)"
1370
1366
raise ValueError (msg )
1371
- elif func in base .cythonized_kernels :
1367
+ elif func in base .cythonized_kernels or func in base . transformation_kernels :
1372
1368
# cythonized transformation or canned "reduction+broadcast"
1373
1369
return getattr (self , func )(* args , ** kwargs )
1374
- elif func in base .transformation_kernels :
1375
- return getattr (self , func )(* args , ** kwargs )
1376
-
1377
1370
# GH 30918
1378
1371
# Use _transform_fast only when we know func is an aggregation
1379
1372
if func in base .reduction_kernels :
@@ -1401,9 +1394,10 @@ def _transform_fast(self, result: DataFrame) -> DataFrame:
1401
1394
# by take operation
1402
1395
ids , _ , ngroup = self .grouper .group_info
1403
1396
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
+ ]
1407
1401
1408
1402
return self .obj ._constructor ._from_arrays (
1409
1403
output , columns = result .columns , index = obj .index
@@ -1462,7 +1456,7 @@ def _transform_item_by_item(self, obj: DataFrame, wrapper) -> DataFrame:
1462
1456
else :
1463
1457
inds .append (i )
1464
1458
1465
- if len ( output ) == 0 :
1459
+ if not output :
1466
1460
raise TypeError ("Transform function invalid for data types" )
1467
1461
1468
1462
columns = obj .columns
0 commit comments