Skip to content

Commit 23f5ce1

Browse files
authored
PERF: Groupby.any/all object dtype (#43675)
1 parent f9b6290 commit 23f5ce1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/groupby/groupby.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1654,9 +1654,12 @@ def objs_to_bool(vals: ArrayLike) -> tuple[np.ndarray, type]:
16541654
if is_object_dtype(vals.dtype):
16551655
# GH#37501: don't raise on pd.NA when skipna=True
16561656
if skipna:
1657-
vals = np.array([bool(x) if not isna(x) else True for x in vals])
1657+
func = np.vectorize(lambda x: bool(x) if not isna(x) else True)
1658+
vals = func(vals)
16581659
else:
1659-
vals = np.array([bool(x) for x in vals])
1660+
vals = vals.astype(bool, copy=False)
1661+
1662+
vals = cast(np.ndarray, vals)
16601663
elif isinstance(vals, BaseMaskedArray):
16611664
vals = vals._data.astype(bool, copy=False)
16621665
else:

0 commit comments

Comments
 (0)