@@ -5998,14 +5998,15 @@ def dropna(
5998
5998
raise KeyError (np .array (subset )[check ].tolist ())
5999
5999
agg_obj = self .take (indices , axis = agg_axis )
6000
6000
6001
- count = agg_obj .count (axis = agg_axis )
6002
-
6003
6001
if thresh is not None :
6002
+ count = agg_obj .count (axis = agg_axis )
6004
6003
mask = count >= thresh
6005
6004
elif how == "any" :
6006
- mask = count == len (agg_obj ._get_axis (agg_axis ))
6005
+ # faster equivalent to 'agg_obj.count(agg_axis) == self.shape[agg_axis]'
6006
+ mask = notna (agg_obj ).all (axis = agg_axis , bool_only = False )
6007
6007
elif how == "all" :
6008
- mask = count > 0
6008
+ # faster equivalent to 'agg_obj.count(agg_axis) > 0'
6009
+ mask = notna (agg_obj ).any (axis = agg_axis , bool_only = False )
6009
6010
else :
6010
6011
if how is not None :
6011
6012
raise ValueError (f"invalid how option: { how } " )
@@ -10035,6 +10036,34 @@ def _get_data() -> DataFrame:
10035
10036
result = self ._constructor_sliced (result , index = labels )
10036
10037
return result
10037
10038
10039
+ def _reduce_axis1 (self , name : str , func , skipna : bool ) -> Series :
10040
+ """
10041
+ Special case for _reduce to try to avoid a potentially-expensive transpose.
10042
+
10043
+ Apply the reduction block-wise along axis=1 and then reduce the resulting
10044
+ 1D arrays.
10045
+ """
10046
+ if name == "all" :
10047
+ result = np .ones (len (self ), dtype = bool )
10048
+ ufunc = np .logical_and
10049
+ elif name == "any" :
10050
+ result = np .zeros (len (self ), dtype = bool )
10051
+ # error: Incompatible types in assignment
10052
+ # (expression has type "_UFunc_Nin2_Nout1[Literal['logical_or'],
10053
+ # Literal[20], Literal[False]]", variable has type
10054
+ # "_UFunc_Nin2_Nout1[Literal['logical_and'], Literal[20],
10055
+ # Literal[True]]")
10056
+ ufunc = np .logical_or # type: ignore[assignment]
10057
+ else :
10058
+ raise NotImplementedError (name )
10059
+
10060
+ for arr in self ._mgr .arrays :
10061
+ middle = func (arr , axis = 0 , skipna = skipna )
10062
+ result = ufunc (result , middle )
10063
+
10064
+ res_ser = self ._constructor_sliced (result , index = self .index )
10065
+ return res_ser
10066
+
10038
10067
def nunique (self , axis : Axis = 0 , dropna : bool = True ) -> Series :
10039
10068
"""
10040
10069
Count number of distinct elements in specified axis.
0 commit comments