Skip to content

Commit 41827fb

Browse files
committed
PERF : #37081 Compute dtypes once for 'any_object' and 'dtype_is_dt'
1 parent 6357ac2 commit 41827fb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pandas/core/frame.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8652,11 +8652,10 @@ def _reduce(
86528652
assert filter_type is None or filter_type == "bool", filter_type
86538653
out_dtype = "bool" if filter_type == "bool" else None
86548654

8655+
own_dtypes = [arr.dtype for arr in self._iter_column_arrays()]
8656+
86558657
dtype_is_dt = np.array(
8656-
[
8657-
is_datetime64_any_dtype(values.dtype)
8658-
for values in self._iter_column_arrays()
8659-
],
8658+
[is_datetime64_any_dtype(dtype) for dtype in own_dtypes],
86608659
dtype=bool,
86618660
)
86628661
if numeric_only is None and name in ["mean", "median"] and dtype_is_dt.any():
@@ -8671,9 +8670,10 @@ def _reduce(
86718670
self = self[cols]
86728671

86738672
any_object = np.array(
8674-
[is_object_dtype(values.dtype) for values in self._iter_column_arrays()],
8673+
[is_object_dtype(dtype) for dtype in own_dtypes],
86758674
dtype=bool,
86768675
).any()
8676+
86778677
# TODO: Make other agg func handle axis=None properly GH#21597
86788678
axis = self._get_axis_number(axis)
86798679
labels = self._get_agg_axis(axis)

0 commit comments

Comments
 (0)