@@ -8617,22 +8617,19 @@ def _reduce(
8617
8617
cols = self .columns [~ dtype_is_dt ]
8618
8618
self = self [cols ]
8619
8619
8620
- if axis is None and filter_type == "bool" :
8621
- labels = None
8622
- constructor = None
8623
- else :
8624
- # TODO: Make other agg func handle axis=None properly
8625
- axis = self ._get_axis_number (axis )
8626
- labels = self ._get_agg_axis (axis )
8627
- constructor = self ._constructor
8620
+ # TODO: Make other agg func handle axis=None properly
8621
+ axis = self ._get_axis_number (axis )
8622
+ labels = self ._get_agg_axis (axis )
8623
+ constructor = self ._constructor
8624
+ assert axis in [0 , 1 ]
8628
8625
8629
8626
def func (values ):
8630
8627
if is_extension_array_dtype (values .dtype ):
8631
8628
return extract_array (values )._reduce (name , skipna = skipna , ** kwds )
8632
8629
else :
8633
8630
return op (values , axis = axis , skipna = skipna , ** kwds )
8634
8631
8635
- def _get_data (axis_matters ) :
8632
+ def _get_data (axis_matters : bool ) -> "DataFrame" :
8636
8633
if filter_type is None :
8637
8634
data = self ._get_numeric_data ()
8638
8635
elif filter_type == "bool" :
@@ -8649,7 +8646,7 @@ def _get_data(axis_matters):
8649
8646
raise NotImplementedError (msg )
8650
8647
return data
8651
8648
8652
- if numeric_only is not None and axis in [ 0 , 1 ] :
8649
+ if numeric_only is not None :
8653
8650
df = self
8654
8651
if numeric_only is True :
8655
8652
df = _get_data (axis_matters = True )
@@ -8675,6 +8672,8 @@ def blk_func(values):
8675
8672
out [:] = coerce_to_dtypes (out .values , df .dtypes )
8676
8673
return out
8677
8674
8675
+ assert numeric_only is None
8676
+
8678
8677
if not self ._is_homogeneous_type or self ._mgr .any_extension_types :
8679
8678
# try to avoid self.values call
8680
8679
@@ -8702,40 +8701,24 @@ def blk_func(values):
8702
8701
result = result .iloc [0 ].rename (None )
8703
8702
return result
8704
8703
8705
- if numeric_only is None :
8706
- data = self
8707
- values = data .values
8708
-
8709
- try :
8710
- result = func (values )
8711
-
8712
- except TypeError :
8713
- # e.g. in nanops trying to convert strs to float
8704
+ data = self
8705
+ values = data .values
8714
8706
8715
- # TODO: why doesnt axis matter here?
8716
- data = _get_data (axis_matters = False )
8717
- labels = data ._get_agg_axis (axis )
8707
+ try :
8708
+ result = func (values )
8718
8709
8719
- values = data .values
8720
- with np .errstate (all = "ignore" ):
8721
- result = func (values )
8710
+ except TypeError :
8711
+ # e.g. in nanops trying to convert strs to float
8722
8712
8723
- else :
8724
- if numeric_only :
8725
- data = _get_data (axis_matters = True )
8726
- labels = data ._get_agg_axis (axis )
8713
+ # TODO: why doesnt axis matter here?
8714
+ data = _get_data (axis_matters = False )
8715
+ labels = data ._get_agg_axis (axis )
8727
8716
8728
- values = data .values
8729
- else :
8730
- data = self
8731
- values = data .values
8732
- result = func (values )
8717
+ values = data .values
8718
+ with np .errstate (all = "ignore" ):
8719
+ result = func (values )
8733
8720
8734
- if filter_type == "bool" and is_object_dtype (values ) and axis is None :
8735
- # work around https://github.com/numpy/numpy/issues/10489
8736
- # TODO: can we de-duplicate parts of this with the next blocK?
8737
- result = np .bool_ (result )
8738
- elif hasattr (result , "dtype" ) and is_object_dtype (result .dtype ):
8721
+ if is_object_dtype (result .dtype ):
8739
8722
try :
8740
8723
if filter_type is None :
8741
8724
result = result .astype (np .float64 )
0 commit comments