@@ -8539,51 +8539,42 @@ def blk_func(values):
8539
8539
out [:] = coerce_to_dtypes (out .values , df .dtypes )
8540
8540
return out
8541
8541
8542
- if not self ._is_homogeneous_type :
8543
- # try to avoid self.values call
8544
-
8545
- if filter_type is None and axis == 0 and len (self ) > 0 :
8546
- # operate column-wise
8547
-
8548
- # numeric_only must be None here, as other cases caught above
8549
- # require len(self) > 0 bc frame_apply messes up empty prod/sum
8550
-
8551
- # this can end up with a non-reduction
8552
- # but not always. if the types are mixed
8553
- # with datelike then need to make sure a series
8554
-
8555
- # we only end up here if we have not specified
8556
- # numeric_only and yet we have tried a
8557
- # column-by-column reduction, where we have mixed type.
8558
- # So let's just do what we can
8559
- from pandas .core .apply import frame_apply
8560
-
8561
- opa = frame_apply (
8562
- self , func = f , result_type = "expand" , ignore_failures = True
8563
- )
8564
- result = opa .get_result ()
8565
- if result .ndim == self .ndim :
8566
- result = result .iloc [0 ].rename (None )
8567
- return result
8568
-
8569
8542
if numeric_only is None :
8570
8543
data = self
8571
8544
values = data .values
8572
-
8573
8545
try :
8574
8546
result = f (values )
8575
8547
8576
8548
except TypeError :
8577
8549
# e.g. in nanops trying to convert strs to float
8578
8550
8551
+ # try by-column first
8552
+ if filter_type is None and axis == 0 :
8553
+ # this can end up with a non-reduction
8554
+ # but not always. if the types are mixed
8555
+ # with datelike then need to make sure a series
8556
+
8557
+ # we only end up here if we have not specified
8558
+ # numeric_only and yet we have tried a
8559
+ # column-by-column reduction, where we have mixed type.
8560
+ # So let's just do what we can
8561
+ from pandas .core .apply import frame_apply
8562
+
8563
+ opa = frame_apply (
8564
+ self , func = f , result_type = "expand" , ignore_failures = True
8565
+ )
8566
+ result = opa .get_result ()
8567
+ if result .ndim == self .ndim :
8568
+ result = result .iloc [0 ]
8569
+ return result
8570
+
8579
8571
# TODO: why doesnt axis matter here?
8580
8572
data = _get_data (axis_matters = False )
8581
8573
labels = data ._get_agg_axis (axis )
8582
8574
8583
8575
values = data .values
8584
8576
with np .errstate (all = "ignore" ):
8585
8577
result = f (values )
8586
-
8587
8578
else :
8588
8579
if numeric_only :
8589
8580
data = _get_data (axis_matters = True )
0 commit comments