-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: uses_mask in group_any_all #52043
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1658,10 +1658,10 @@ def objs_to_bool(vals: ArrayLike) -> tuple[np.ndarray, type]: | |
def result_to_bool( | ||
result: np.ndarray, | ||
inference: type, | ||
nullable: bool = False, | ||
result_mask, | ||
) -> ArrayLike: | ||
if nullable: | ||
return BooleanArray(result.astype(bool, copy=False), result == -1) | ||
if result_mask is not None: | ||
return BooleanArray(result.astype(bool, copy=False), result_mask) | ||
else: | ||
return result.astype(inference, copy=False) | ||
|
||
|
@@ -1939,10 +1939,8 @@ def _preprocessing(values): | |
return values._data, None | ||
return values, None | ||
|
||
def _postprocessing( | ||
vals, inference, nullable: bool = False, result_mask=None | ||
) -> ArrayLike: | ||
if nullable: | ||
def _postprocessing(vals, inference, result_mask=None) -> ArrayLike: | ||
if result_mask is not None: | ||
if result_mask.ndim == 2: | ||
result_mask = result_mask[:, 0] | ||
return FloatingArray(np.sqrt(vals), result_mask.view(np.bool_)) | ||
|
@@ -3716,13 +3714,11 @@ def blk_func(values: ArrayLike) -> ArrayLike: | |
mask = mask.reshape(-1, 1) | ||
func = partial(func, mask=mask) | ||
|
||
if how != "std": | ||
is_nullable = isinstance(values, BaseMaskedArray) | ||
func = partial(func, nullable=is_nullable) | ||
|
||
elif isinstance(values, BaseMaskedArray): | ||
result_mask = None | ||
if isinstance(values, BaseMaskedArray): | ||
result_mask = np.zeros(result.shape, dtype=np.bool_) | ||
func = partial(func, result_mask=result_mask) | ||
|
||
func = partial(func, result_mask=result_mask) | ||
|
||
# Call func to modify result in place | ||
if how == "std": | ||
|
@@ -3733,14 +3729,12 @@ def blk_func(values: ArrayLike) -> ArrayLike: | |
if values.ndim == 1: | ||
assert result.shape[1] == 1, result.shape | ||
result = result[:, 0] | ||
if result_mask is not None: | ||
assert result_mask.shape[1] == 1, result_mask.shape | ||
result_mask = result_mask[:, 0] | ||
|
||
if post_processing: | ||
pp_kwargs: dict[str, bool | np.ndarray] = {} | ||
pp_kwargs["nullable"] = isinstance(values, BaseMaskedArray) | ||
if how == "std" and pp_kwargs["nullable"]: | ||
pp_kwargs["result_mask"] = result_mask | ||
|
||
result = post_processing(result, inferences, **pp_kwargs) | ||
result = post_processing(result, inferences, result_mask=result_mask) | ||
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. You'll probably have to remove the flag is_nullable for the std post_processing function (the default is False) and check for result_mask is not None |
||
|
||
if how == "std" and is_datetimelike: | ||
values = cast("DatetimeArray | TimedeltaArray", values) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For any: If NA is encountered as first value in the group you are setting the mask to 1 here but you don't reset it if you find another value in the group that is not NA. You'll have to update the result_mask if you find another value.
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.
Oh OK. I missed that we are checking
out[lab, j] != ...
here as opposed tovalues[i, j] != ...
. Thanks.