@@ -638,10 +638,10 @@ def _can_fast_transpose(self) -> bool:
638
638
"""
639
639
Can we transpose this DataFrame without creating any new array objects.
640
640
"""
641
- if self ._data .any_extension_types :
641
+ if self ._mgr .any_extension_types :
642
642
# TODO(EA2D) special case would be unnecessary with 2D EAs
643
643
return False
644
- return len (self ._data .blocks ) == 1
644
+ return len (self ._mgr .blocks ) == 1
645
645
646
646
# ----------------------------------------------------------------------
647
647
# Rendering Methods
@@ -2879,7 +2879,7 @@ def _get_column_array(self, i: int) -> ArrayLike:
2879
2879
Get the values of the i'th column (ndarray or ExtensionArray, as stored
2880
2880
in the Block)
2881
2881
"""
2882
- return self ._data .iget_values (i )
2882
+ return self ._mgr .iget_values (i )
2883
2883
2884
2884
def _iter_column_arrays (self ) -> Iterator [ArrayLike ]:
2885
2885
"""
@@ -4911,7 +4911,7 @@ def _maybe_casted_values(index, labels=None):
4911
4911
4912
4912
@doc (NDFrame .isna , klass = _shared_doc_kwargs ["klass" ])
4913
4913
def isna (self ) -> DataFrame :
4914
- result = self ._constructor (self ._data .isna (func = isna ))
4914
+ result = self ._constructor (self ._mgr .isna (func = isna ))
4915
4915
return result .__finalize__ (self , method = "isna" )
4916
4916
4917
4917
@doc (NDFrame .isna , klass = _shared_doc_kwargs ["klass" ])
@@ -8575,6 +8575,7 @@ def _reduce(
8575
8575
):
8576
8576
8577
8577
assert filter_type is None or filter_type == "bool" , filter_type
8578
+ out_dtype = "bool" if filter_type == "bool" else None
8578
8579
8579
8580
dtype_is_dt = np .array (
8580
8581
[
@@ -8594,10 +8595,9 @@ def _reduce(
8594
8595
cols = self .columns [~ dtype_is_dt ]
8595
8596
self = self [cols ]
8596
8597
8597
- # TODO: Make other agg func handle axis=None properly
8598
+ # TODO: Make other agg func handle axis=None properly GH#21597
8598
8599
axis = self ._get_axis_number (axis )
8599
8600
labels = self ._get_agg_axis (axis )
8600
- constructor = self ._constructor
8601
8601
assert axis in [0 , 1 ]
8602
8602
8603
8603
def func (values ):
@@ -8606,18 +8606,19 @@ def func(values):
8606
8606
else :
8607
8607
return op (values , axis = axis , skipna = skipna , ** kwds )
8608
8608
8609
+ def blk_func (values ):
8610
+ if isinstance (values , ExtensionArray ):
8611
+ return values ._reduce (name , skipna = skipna , ** kwds )
8612
+ else :
8613
+ return op (values , axis = 1 , skipna = skipna , ** kwds )
8614
+
8609
8615
def _get_data () -> DataFrame :
8610
8616
if filter_type is None :
8611
8617
data = self ._get_numeric_data ()
8612
- elif filter_type == "bool" :
8618
+ else :
8613
8619
# GH#25101, GH#24434
8620
+ assert filter_type == "bool"
8614
8621
data = self ._get_bool_data ()
8615
- else : # pragma: no cover
8616
- msg = (
8617
- f"Generating numeric_only data with filter_type { filter_type } "
8618
- "not supported."
8619
- )
8620
- raise NotImplementedError (msg )
8621
8622
return data
8622
8623
8623
8624
if numeric_only is not None :
@@ -8628,14 +8629,6 @@ def _get_data() -> DataFrame:
8628
8629
df = df .T
8629
8630
axis = 0
8630
8631
8631
- out_dtype = "bool" if filter_type == "bool" else None
8632
-
8633
- def blk_func (values ):
8634
- if isinstance (values , ExtensionArray ):
8635
- return values ._reduce (name , skipna = skipna , ** kwds )
8636
- else :
8637
- return op (values , axis = 1 , skipna = skipna , ** kwds )
8638
-
8639
8632
# After possibly _get_data and transposing, we are now in the
8640
8633
# simple case where we can use BlockManager.reduce
8641
8634
res = df ._mgr .reduce (blk_func )
@@ -8651,11 +8644,10 @@ def blk_func(values):
8651
8644
if not self ._is_homogeneous_type or self ._mgr .any_extension_types :
8652
8645
# try to avoid self.values call
8653
8646
8654
- if filter_type is None and axis == 0 and len ( self ) > 0 :
8647
+ if filter_type is None and axis == 0 :
8655
8648
# operate column-wise
8656
8649
8657
8650
# numeric_only must be None here, as other cases caught above
8658
- # require len(self) > 0 bc frame_apply messes up empty prod/sum
8659
8651
8660
8652
# this can end up with a non-reduction
8661
8653
# but not always. if the types are mixed
@@ -8691,19 +8683,17 @@ def blk_func(values):
8691
8683
with np .errstate (all = "ignore" ):
8692
8684
result = func (values )
8693
8685
8694
- if is_object_dtype (result .dtype ):
8686
+ if filter_type == "bool" and notna (result ).all ():
8687
+ result = result .astype (np .bool_ )
8688
+ elif filter_type is None and is_object_dtype (result .dtype ):
8695
8689
try :
8696
- if filter_type is None :
8697
- result = result .astype (np .float64 )
8698
- elif filter_type == "bool" and notna (result ).all ():
8699
- result = result .astype (np .bool_ )
8690
+ result = result .astype (np .float64 )
8700
8691
except (ValueError , TypeError ):
8701
8692
# try to coerce to the original dtypes item by item if we can
8702
8693
if axis == 0 :
8703
8694
result = coerce_to_dtypes (result , data .dtypes )
8704
8695
8705
- if constructor is not None :
8706
- result = self ._constructor_sliced (result , index = labels )
8696
+ result = self ._constructor_sliced (result , index = labels )
8707
8697
return result
8708
8698
8709
8699
def nunique (self , axis = 0 , dropna = True ) -> Series :
0 commit comments