@@ -573,13 +573,19 @@ def _transform_general(self, func, *args, **kwargs):
573
573
def transform (self , func , * args , ** kwargs ):
574
574
575
575
# optimized transforms
576
- func = self ._is_cython_func (func ) or func
576
+ func = self ._get_cython_func (func ) or func
577
+
577
578
if isinstance (func , str ):
578
- if func in base .cython_transforms :
579
- # cythonized transform
579
+ if not (func in base .transform_kernel_whitelist ):
580
+ msg = "'{func}' is not a valid function name for transform(name)"
581
+ raise ValueError (msg .format (func = func ))
582
+ if func in base .cythonized_kernels :
583
+ # cythonized transformation or canned "reduction+broadcast"
580
584
return getattr (self , func )(* args , ** kwargs )
581
585
else :
582
- # cythonized aggregation and merge
586
+ # If func is a reduction, we need to broadcast the
587
+ # result to the whole group. Compute func result
588
+ # and deal with possible broadcasting below.
583
589
result = getattr (self , func )(* args , ** kwargs )
584
590
else :
585
591
return self ._transform_general (func , * args , ** kwargs )
@@ -590,7 +596,7 @@ def transform(self, func, *args, **kwargs):
590
596
591
597
obj = self ._obj_with_exclusions
592
598
593
- # nuiscance columns
599
+ # nuisance columns
594
600
if not result .columns .equals (obj .columns ):
595
601
return self ._transform_general (func , * args , ** kwargs )
596
602
@@ -853,7 +859,7 @@ def aggregate(self, func_or_funcs=None, *args, **kwargs):
853
859
if relabeling :
854
860
ret .columns = columns
855
861
else :
856
- cyfunc = self ._is_cython_func (func_or_funcs )
862
+ cyfunc = self ._get_cython_func (func_or_funcs )
857
863
if cyfunc and not args and not kwargs :
858
864
return getattr (self , cyfunc )()
859
865
@@ -1005,15 +1011,19 @@ def _aggregate_named(self, func, *args, **kwargs):
1005
1011
@Substitution (klass = "Series" , selected = "A." )
1006
1012
@Appender (_transform_template )
1007
1013
def transform (self , func , * args , ** kwargs ):
1008
- func = self ._is_cython_func (func ) or func
1014
+ func = self ._get_cython_func (func ) or func
1009
1015
1010
- # if string function
1011
1016
if isinstance (func , str ):
1012
- if func in base .cython_transforms :
1013
- # cythonized transform
1017
+ if not (func in base .transform_kernel_whitelist ):
1018
+ msg = "'{func}' is not a valid function name for transform(name)"
1019
+ raise ValueError (msg .format (func = func ))
1020
+ if func in base .cythonized_kernels :
1021
+ # cythonized transform or canned "agg+broadcast"
1014
1022
return getattr (self , func )(* args , ** kwargs )
1015
1023
else :
1016
- # cythonized aggregation and merge
1024
+ # If func is a reduction, we need to broadcast the
1025
+ # result to the whole group. Compute func result
1026
+ # and deal with possible broadcasting below.
1017
1027
return self ._transform_fast (
1018
1028
lambda : getattr (self , func )(* args , ** kwargs ), func
1019
1029
)
0 commit comments