@@ -7915,12 +7915,18 @@ def _get_data(axis_matters):
7915
7915
raise NotImplementedError (msg )
7916
7916
return data
7917
7917
7918
+ def blk_func (values ):
7919
+ if isinstance (values , ExtensionArray ):
7920
+ return values ._reduce (name , skipna = skipna , ** kwds )
7921
+ else :
7922
+ return op (values , axis = 1 , skipna = skipna , ** kwds )
7923
+
7918
7924
if axis == 0 and column_wise :
7919
7925
# column-wise reduction
7920
7926
df = self
7921
7927
if numeric_only is True :
7922
7928
df = _get_data (axis_matters = True )
7923
- return df ._reduce_columns (op , name , skipna = skipna , ** kwds )
7929
+ return df ._reduce_columns (blk_func )
7924
7930
7925
7931
if numeric_only is not None and axis in [0 , 1 ]:
7926
7932
df = self
@@ -7932,12 +7938,6 @@ def _get_data(axis_matters):
7932
7938
7933
7939
out_dtype = "bool" if filter_type == "bool" else None
7934
7940
7935
- def blk_func (values ):
7936
- if isinstance (values , ExtensionArray ):
7937
- return values ._reduce (name , skipna = skipna , ** kwds )
7938
- else :
7939
- return op (values , axis = 1 , skipna = skipna , ** kwds )
7940
-
7941
7941
# After possibly _get_data and transposing, we are now in the
7942
7942
# simple case where we can use BlockManager._reduce
7943
7943
res = df ._data .reduce (blk_func )
@@ -8018,47 +8018,27 @@ def blk_func(values):
8018
8018
result = self ._constructor_sliced (result , index = labels )
8019
8019
return result
8020
8020
8021
- def _reduce_columns (self , op , name , skipna = True , ** kwds ):
8021
+ def _reduce_columns (self , op ):
8022
8022
"""
8023
8023
Reduce DataFrame column-wise.
8024
8024
8025
8025
Parameters
8026
8026
----------
8027
8027
op : func
8028
- The reducing function to be called on the values. Only used
8029
- for columns backed by a numpy ndarray.
8030
- name : str
8031
- The name of the reduction.
8032
- skipna, **kwds : keywords to pass to the `op` function
8028
+ The reducing function to be called on the values.
8033
8029
8034
8030
Returns
8035
8031
-------
8036
8032
Series
8037
8033
"""
8038
8034
result = []
8039
8035
8040
- for arr in self ._iter_arrays ():
8041
- if isinstance (arr , ExtensionArray ):
8042
- # dispatch to ExtensionArray interface
8043
- val = arr ._reduce (name , skipna = skipna , ** kwds )
8044
- else :
8045
- # dispatch to numpy arrays
8046
- with np .errstate (all = "ignore" ):
8047
- val = op (arr , skipna = skipna , ** kwds )
8048
-
8036
+ for i in range (len (self .columns )):
8037
+ val = op (self ._data .iget_values (i ))
8049
8038
result .append (val )
8050
8039
8051
8040
return self ._constructor_sliced (result , index = self .columns )
8052
8041
8053
- def _iter_arrays (self ):
8054
- """
8055
- Iterate over the arrays of all columns in order.
8056
-
8057
- This returns the values as stored in the Block (ndarray or ExtensionArray).
8058
- """
8059
- for i in range (len (self .columns )):
8060
- yield self ._data .iget_values (i )
8061
-
8062
8042
def nunique (self , axis = 0 , dropna = True ) -> Series :
8063
8043
"""
8064
8044
Count distinct observations over requested axis.
0 commit comments