BUG: Fixed where
keyword for np.mean
& np.var
methods
#18612
Merged
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.
Backport of #18560.
Addresses #18552
I've managed to fix
where
keyword issue by refactoring those if statements.So the
rcount
is a scalar whenwhere
is not provided as we reduce equal number of elements for given axis (or axes). So the firstand
statement prevents from illegal comparison of array to 0 value that caused original error. If thewhere
clause is provided andrcount
is an array (as we might want to reduce different number of elements along axis due to masking) then we check secondand
statement if any of those reduce groups are zero. I also maintained this micro-optimization to avoid calling_any(rcount == 0)
whenwhere is True
and not zero.Is this correct?
Also I had to change
umr_any
to_any
as I think there is another bug there (orumr_any
shouldn't be used there).np.any
withoutaxis
parameter evaluates to scalar value (that can be used inif
statement). Butumr_any
does not behave that way - it only reduces one dimension. Here's code for reproducing:Here's a colab reproduction: https://colab.research.google.com/drive/1UJi6E50zzaLu2nZQWMEFHPLZnq2v6pzT?usp=sharing
Thank you for any help!
Fixed keyword bug
Added test case
Reverted to original notation
Added tests for var and std
Closes gh-18552