Skip to content
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

Merged
merged 2 commits into from Feb 9, 2022

Conversation

seberg
Copy link
Member

@seberg seberg commented Feb 9, 2022

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

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 seberg added the 09 - Backport-Candidate PRs tagged should be backported label Feb 9, 2022
@@ -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")
Copy link
Member Author

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)

Copy link
Contributor

@rossbar rossbar left a 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

numpy/core/src/umath/dispatching.c Outdated Show resolved Hide resolved
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
@rossbar rossbar merged commit d7929b3 into numpy:main Feb 9, 2022
@seberg seberg deleted the disallow-strings-in-logical-ufuncs branch February 9, 2022 22:17
@jakirkham
Copy link
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>
@charris charris added 06 - Regression and removed 09 - Backport-Candidate PRs tagged should be backported labels Mar 2, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Vague error message from ufunc np.any
4 participants