-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Fix piecewise implicit return type conversion #24309
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
base: main
Are you sure you want to change the base?
Conversation
|
||
func_val = func(vals, *args, **kw) | ||
y = y.astype(asarray(func_val).dtype) | ||
y[cond] = func_val |
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.
A few thoughts here:
- We probably need some core devs to chime in on whether a behavior change is justified from NumPy's perspective. I don't see many of the regulars discussing in either of the issues at this stage. We'd be breaking from presumably long-term documented behavior, even if it is a bit odd.
- Even if folks were in favor of a change that is not backwards compatible, on the basis that it might be considered a "bug fix," we'd almost certainly need to add some tests for various scenarios.
- What happens when the functions in
funclist
output values with dtypes that can't safely be combined?- Should we even convert
out
toobject
in weird cases? - Should we allow
out
to have its dtype size reduced relative tox
if all functions infunclist
return smaller width types than current type ofx
? I can imagine this breaking some control flows in potentially surprising ways perhaps. - is there anything to stop one of the functions in
funclist
from returning different types in different cases? You can pretty much make these functions do whatever you want with the return type, right? So, wouldn't it be hard to rigidly define what happens in these cases? Oof.
- Should we even convert
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.
@tylerjereddy Thank you for reviewing the code. You're right the changes do alter the traditional behavior. One thing I could think of, to support backward compatibility, is to introduce a flag which could allow the user to specify if they want to match the output dtype with the function output dtype or match it with the input dtype. I believe this could potentially answer the second point that you made. And finally, I can modify the implementation to match the piecewise output dtype with highest precesion output of all the functions in the funclist, but you're right we would require additional tests to make sure that there isn't any unexpected behavior. But yeah definetly need some intput from the core developers on the issue since any changes would result in modifying traditional behavior.
Closes #24155 and #19755.
Fix for the bug which resulted in the output of piecewise function to be same dtype as the input. Now, the output dtype matches with the dtype of funclist output instead of the input.