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
API: Disallow strings in logical ufuncs #21024
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
@@ -2134,7 +2134,7 @@ def test_logical_ufuncs_mixed_object_signatures(self, ufunc, signature): | |||
[np.logical_and, np.logical_or, np.logical_xor]) | |||
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") |
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.
Void tests the same thing and defines the bool cast somewhat reasonably (anything that is not all NULL)
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.
LGTM less a typo - if you're done with this @seberg I'm happy to put it in
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Thanks Sebastian for the PR and Ross for the review! 😄 |
* 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>
* 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>
* 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 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