@@ -7996,42 +7996,52 @@ def blk_func(values):
7996
7996
out [:] = coerce_to_dtypes (out .values , df .dtypes )
7997
7997
return out
7998
7998
7999
+ if not self ._is_homogeneous_type :
8000
+ # try to avoid self.values call
8001
+
8002
+ if filter_type is None and axis == 0 and len (self ) > 0 :
8003
+ # operate column-wise
8004
+
8005
+ # numeric_only must be None here, as other cases caught above
8006
+ # require len(self) > 0 bc frame_apply messes up empty prod/sum
8007
+
8008
+ # this can end up with a non-reduction
8009
+ # but not always. if the types are mixed
8010
+ # with datelike then need to make sure a series
8011
+
8012
+ # we only end up here if we have not specified
8013
+ # numeric_only and yet we have tried a
8014
+ # column-by-column reduction, where we have mixed type.
8015
+ # So let's just do what we can
8016
+ from pandas .core .apply import frame_apply
8017
+
8018
+ opa = frame_apply (
8019
+ self , func = f , result_type = "expand" , ignore_failures = True
8020
+ )
8021
+ result = opa .get_result ()
8022
+ if result .ndim == self .ndim :
8023
+ result = result .iloc [0 ].rename (None )
8024
+ return result
8025
+
8026
+ data = self
7999
8027
if numeric_only is None :
8000
8028
data = self
8001
8029
values = data .values
8030
+
8002
8031
try :
8003
8032
result = f (values )
8004
8033
8005
8034
except TypeError :
8006
8035
# e.g. in nanops trying to convert strs to float
8007
8036
8008
- # try by-column first
8009
- if filter_type is None and axis == 0 :
8010
- # this can end up with a non-reduction
8011
- # but not always. if the types are mixed
8012
- # with datelike then need to make sure a series
8013
-
8014
- # we only end up here if we have not specified
8015
- # numeric_only and yet we have tried a
8016
- # column-by-column reduction, where we have mixed type.
8017
- # So let's just do what we can
8018
- from pandas .core .apply import frame_apply
8019
-
8020
- opa = frame_apply (
8021
- self , func = f , result_type = "expand" , ignore_failures = True
8022
- )
8023
- result = opa .get_result ()
8024
- if result .ndim == self .ndim :
8025
- result = result .iloc [0 ]
8026
- return result
8027
-
8028
8037
# TODO: why doesnt axis matter here?
8029
8038
data = _get_data (axis_matters = False )
8030
8039
labels = data ._get_agg_axis (axis )
8031
8040
8032
8041
values = data .values
8033
8042
with np .errstate (all = "ignore" ):
8034
8043
result = f (values )
8044
+
8035
8045
else :
8036
8046
if numeric_only :
8037
8047
data = _get_data (axis_matters = True )
0 commit comments