-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
BUG: Fixed regressions in np.piecewise in ref to #5737 and #5729. #7145
Conversation
…#5729. Added unit tests for these conditions.
@@ -944,11 +944,15 @@ def piecewise(x, condlist, funclist, *args, **kw): | |||
condlist = condlist.T | |||
if n == n2 - 1: # compute the "otherwise" condition. | |||
totlist = np.logical_or.reduce(condlist, axis=0) | |||
condlist = np.vstack([condlist, ~totlist]) | |||
try: |
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 you do this without using try...except
? Using exception handling for flow control is kind of ugly. Also, there should be an explanation of why the alternative is correct.
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.
Yes it should be possible as we can check for the number of dimensions. Thanks for the feedback. I agree the try...except
block is ugly and even more so without a specific exception.
Thanks @bastula . |
Fixed regressions in np.piecewise that were generated as a result of the 0d fixes in #4792.
Unit tests were appropriately added.
The fix for #5737 was created by reusing the old condition creation method which works better for multidimensional arrays.
The fix for #5729 was created by removing the n != n2 as it is not necessary and piecewise still works with the same expected behavior (confirmed via unit tests).