@@ -9826,26 +9826,28 @@ def _reduce(
9826
9826
assert filter_type is None or filter_type == "bool" , filter_type
9827
9827
out_dtype = "bool" if filter_type == "bool" else None
9828
9828
9829
- own_dtypes = [arr .dtype for arr in self ._iter_column_arrays ()]
9829
+ if numeric_only is None and name in ["mean" , "median" ]:
9830
+ own_dtypes = [arr .dtype for arr in self ._mgr .arrays ]
9830
9831
9831
- dtype_is_dt = np .array (
9832
- [is_datetime64_any_dtype (dtype ) for dtype in own_dtypes ],
9833
- dtype = bool ,
9834
- )
9835
- if numeric_only is None and name in ["mean" , "median" ] and dtype_is_dt .any ():
9836
- warnings .warn (
9837
- "DataFrame.mean and DataFrame.median with numeric_only=None "
9838
- "will include datetime64 and datetime64tz columns in a "
9839
- "future version." ,
9840
- FutureWarning ,
9841
- stacklevel = 5 ,
9832
+ dtype_is_dt = np .array (
9833
+ [is_datetime64_any_dtype (dtype ) for dtype in own_dtypes ],
9834
+ dtype = bool ,
9842
9835
)
9843
- # Non-copy equivalent to
9844
- # cols = self.columns[~dtype_is_dt]
9845
- # self = self[cols]
9846
- predicate = lambda x : not is_datetime64_any_dtype (x .dtype )
9847
- mgr = self ._mgr ._get_data_subset (predicate )
9848
- self = type (self )(mgr )
9836
+ if dtype_is_dt .any ():
9837
+ warnings .warn (
9838
+ "DataFrame.mean and DataFrame.median with numeric_only=None "
9839
+ "will include datetime64 and datetime64tz columns in a "
9840
+ "future version." ,
9841
+ FutureWarning ,
9842
+ stacklevel = 5 ,
9843
+ )
9844
+ # Non-copy equivalent to
9845
+ # dt64_cols = self.dtypes.apply(is_datetime64_any_dtype)
9846
+ # cols = self.columns[~dt64_cols]
9847
+ # self = self[cols]
9848
+ predicate = lambda x : not is_datetime64_any_dtype (x .dtype )
9849
+ mgr = self ._mgr ._get_data_subset (predicate )
9850
+ self = type (self )(mgr )
9849
9851
9850
9852
# TODO: Make other agg func handle axis=None properly GH#21597
9851
9853
axis = self ._get_axis_number (axis )
0 commit comments