-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: groupby.any/all with object dtype #50623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1774,22 +1774,13 @@ def _bool_agg(self, val_test: Literal["any", "all"], skipna: bool): | |
""" | ||
|
||
def objs_to_bool(vals: ArrayLike) -> tuple[np.ndarray, type]: | ||
if is_object_dtype(vals.dtype): | ||
if is_object_dtype(vals.dtype) and skipna: | ||
# GH#37501: don't raise on pd.NA when skipna=True | ||
if skipna: | ||
func = np.vectorize( | ||
lambda x: bool(x) if not isna(x) else True, otypes=[bool] | ||
) | ||
vals = func(vals) | ||
else: | ||
vals = vals.astype(bool, copy=False) | ||
|
||
vals = cast(np.ndarray, vals) | ||
vals = vals.copy() | ||
vals[isna(vals)] = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment that we will re-compute a mask later on? Hard to follow why setting = True is valid if you don't know that. Additionally, would it be faster to check if isna(vale).any() before making a copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment and skipped the copy when possible. Seems to save a bit more more (~5%). |
||
elif isinstance(vals, BaseMaskedArray): | ||
vals = vals._data.astype(bool, copy=False) | ||
else: | ||
vals = vals.astype(bool, copy=False) | ||
|
||
vals = vals._data | ||
vals = vals.astype(bool, copy=False) | ||
return vals.view(np.int8), bool | ||
|
||
def result_to_bool( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use PR # here assuming there is no issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thx