API: Disallow strings in logical ufuncs#21024
Merged
rossbar merged 2 commits intonumpy:mainfrom Feb 9, 2022
Merged
Conversation
This restores pre 1.22 NumPy behaviour for strings passed into logical ufuncs. Logical ufuncs should be able to cast inputs to booleans without modifying their results. Thus they do this now (in NumPy 1.22+). The problem is that string to bool casts are very strange in NumPy currently. This should be reverted/removed once string to bool casts are well defined. But until then, it seems more reasonable to just reject strings. Closes numpygh-20898
seberg
commented
Feb 9, 2022
| def test_logical_ufuncs_support_anything(self, ufunc): | ||
| # The logical ufuncs support even input that can't be promoted: | ||
| a = np.array('1') | ||
| a = np.array(b'1', dtype="V3") |
Member
Author
There was a problem hiding this comment.
Void tests the same thing and defines the bool cast somewhat reasonably (anything that is not all NULL)
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Contributor
|
Thanks Sebastian for the PR and Ross for the review! 😄 |
charris
pushed a commit
to charris/numpy
that referenced
this pull request
Mar 2, 2022
* API: Disallow strings in logical ufuncs This restores pre 1.22 NumPy behaviour for strings passed into logical ufuncs. Logical ufuncs should be able to cast inputs to booleans without modifying their results. Thus they do this now (in NumPy 1.22+). The problem is that string to bool casts are very strange in NumPy currently. This should be reverted/removed once string to bool casts are well defined. But until then, it seems more reasonable to just reject strings. Closes numpygh-20898 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
melissawm
pushed a commit
to melissawm/numpy
that referenced
this pull request
Apr 12, 2022
* API: Disallow strings in logical ufuncs This restores pre 1.22 NumPy behaviour for strings passed into logical ufuncs. Logical ufuncs should be able to cast inputs to booleans without modifying their results. Thus they do this now (in NumPy 1.22+). The problem is that string to bool casts are very strange in NumPy currently. This should be reverted/removed once string to bool casts are well defined. But until then, it seems more reasonable to just reject strings. Closes numpygh-20898 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
seberg
added a commit
to seberg/numpy
that referenced
this pull request
Apr 24, 2022
* API: Disallow strings in logical ufuncs This restores pre 1.22 NumPy behaviour for strings passed into logical ufuncs. Logical ufuncs should be able to cast inputs to booleans without modifying their results. Thus they do this now (in NumPy 1.22+). The problem is that string to bool casts are very strange in NumPy currently. This should be reverted/removed once string to bool casts are well defined. But until then, it seems more reasonable to just reject strings. Closes numpygh-20898 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
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.
This restores pre 1.22 NumPy behaviour for strings passed into logical
ufuncs. Logical ufuncs should be able to cast inputs to booleans
without modifying their results.
Thus they do this now (in NumPy 1.22+). The problem is that string to
bool casts are very strange in NumPy currently.
This should be reverted/removed once string to bool casts are well
defined. But until then, it seems more reasonable to just reject
strings.
Closes gh-20898