Skip to content

API: Disallow strings in logical ufuncs#21024

Merged
rossbar merged 2 commits intonumpy:mainfrom
seberg:disallow-strings-in-logical-ufuncs
Feb 9, 2022
Merged

API: Disallow strings in logical ufuncs#21024
rossbar merged 2 commits intonumpy:mainfrom
seberg:disallow-strings-in-logical-ufuncs

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
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

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