BUG: Fixed where keyword for np.mean & np.var methods#18612
Merged
charris merged 1 commit intonumpy:maintenance/1.20.xfrom Mar 14, 2021
Merged
BUG: Fixed where keyword for np.mean & np.var methods#18612charris merged 1 commit intonumpy:maintenance/1.20.xfrom
where keyword for np.mean & np.var methods#18612charris merged 1 commit intonumpy:maintenance/1.20.xfrom
Conversation
…mpygh-18560) * Fixed keyword bug * Added test case * Reverted to original notation * Added tests for var and std Closes numpygh-18552
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
wherekeyword issue by refactoring those if statements.So the
rcountis a scalar whenwhereis not provided as we reduce equal number of elements for given axis (or axes). So the firstandstatement prevents from illegal comparison of array to 0 value that caused original error. If thewhereclause is provided andrcountis an array (as we might want to reduce different number of elements along axis due to masking) then we check secondandstatement if any of those reduce groups are zero. I also maintained this micro-optimization to avoid calling_any(rcount == 0)whenwhere is Trueand not zero.Is this correct?
Also I had to change
umr_anyto_anyas I think there is another bug there (orumr_anyshouldn't be used there).np.anywithoutaxisparameter evaluates to scalar value (that can be used inifstatement). Butumr_anydoes 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