@@ -7606,6 +7606,23 @@ def _reduce(
7606
7606
def f (x ):
7607
7607
return op (x , axis = axis , skipna = skipna , ** kwds )
7608
7608
7609
+ def _get_data (axis_matters ):
7610
+ if filter_type is None or filter_type == "numeric" :
7611
+ data = self ._get_numeric_data ()
7612
+ elif filter_type == "bool" :
7613
+ if axis_matters :
7614
+ # GH#25101, GH#24434
7615
+ data = self ._get_bool_data () if axis == 0 else self
7616
+ else :
7617
+ data = self ._get_bool_data ()
7618
+ else : # pragma: no cover
7619
+ msg = (
7620
+ "Generating numeric_only data with filter_type {f}"
7621
+ "not supported." .format (f = filter_type )
7622
+ )
7623
+ raise NotImplementedError (msg )
7624
+ return data
7625
+
7609
7626
if numeric_only is None :
7610
7627
values = self .values
7611
7628
try :
@@ -7616,7 +7633,7 @@ def f(x):
7616
7633
# TODO: combine with hasattr(result, 'dtype') further down
7617
7634
# hard since we don't have `values` down there.
7618
7635
result = np .bool_ (result )
7619
- except TypeError as err :
7636
+ except TypeError :
7620
7637
# e.g. in nanops trying to convert strs to float
7621
7638
7622
7639
# try by-column first
@@ -7639,31 +7656,15 @@ def f(x):
7639
7656
result = result .iloc [0 ]
7640
7657
return result
7641
7658
7642
- if filter_type is None or filter_type == "numeric" :
7643
- data = self ._get_numeric_data ()
7644
- elif filter_type == "bool" :
7645
- data = self ._get_bool_data ()
7646
- else : # pragma: no cover
7647
- raise NotImplementedError (
7648
- "Handling exception with filter_type {f} not"
7649
- "implemented." .format (f = filter_type )
7650
- ) from err
7659
+ # TODO: why doesnt axis matter here?
7660
+ data = _get_data (axis_matters = False )
7651
7661
with np .errstate (all = "ignore" ):
7652
7662
result = f (data .values )
7653
7663
labels = data ._get_agg_axis (axis )
7654
7664
else :
7655
7665
if numeric_only :
7656
- if filter_type is None or filter_type == "numeric" :
7657
- data = self ._get_numeric_data ()
7658
- elif filter_type == "bool" :
7659
- # GH 25101, # GH 24434
7660
- data = self ._get_bool_data () if axis == 0 else self
7661
- else : # pragma: no cover
7662
- msg = (
7663
- "Generating numeric_only data with filter_type {f}"
7664
- "not supported." .format (f = filter_type )
7665
- )
7666
- raise NotImplementedError (msg )
7666
+ data = _get_data (axis_matters = True )
7667
+
7667
7668
values = data .values
7668
7669
labels = data ._get_agg_axis (axis )
7669
7670
else :
0 commit comments