Repository navigation
ENH: Refactor numpy ** operators for numpy scalar integer powers - #8231
Merged
Merged
Conversation
This change is the upshot of discussion on the numpy mailing list where it was decided that a numpy scalar integer raised to a negative integer power should raise a ValueError, as do Numpy arrays. In particular, we want numpy scalars and numpy 0-d arrays to have similar behavior. Previously zero was returned for this case.
Member
Author
|
OK, I've done an almost minimal change for this PR. The whole |
Member
Author
|
Will merge soonish for 1.12.0. |
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.
The previous behavior depended on whether numpy scalar integers or numpy integer arrays were involved.
For arrays
For scalars
All of these cases now raise a
ValueErrorexcept for those integer combinations whose common type is float, for instance uint64 and int8. It was felt that a simple rule was the best way to go rather than have special exceptions for the integer units. If you need negative powers, use an inexact type.Note that the
np.powerufunc is used for everything. At this point I think it is more important to settle the behavior than optimize for speed. There are now some bits of code I left in that are currently unused.