BUG: fix for string missing data in stringdtype cast to bool and nonzero - #32418
Merged
Merged
Conversation
ngoldbaum
force-pushed
the
stringdtype-na-bug
branch
from
August 26, 2026 19:46
939acee to
06b24de
Compare
MaanasArora
approved these changes
Aug 27, 2026
MaanasArora
left a comment
Contributor
There was a problem hiding this comment.
Thanks, LGTM. Since we're not backporting, just a few adjacent simplifications, but totally happy to merge as-is if you'd rather keep this tightly scoped.
ngoldbaum
force-pushed
the
stringdtype-na-bug
branch
from
August 27, 2026 21:09
06b24de to
8906961
Compare
Member
Author
|
Thanks @MaanasArora! This also made me realize I can put the truthiness test into a shared helper and make this PR net-negative on LoC, even with the test 😎 |
ngoldbaum
force-pushed
the
stringdtype-na-bug
branch
from
August 27, 2026 21:14
8906961 to
9130824
Compare
MaanasArora
reviewed
Aug 28, 2026
Contributor
There was a problem hiding this comment.
Thank you @ngoldbaum , that's a feat indeed :D
I traced through everything and it still looks great to me, in it goes!
| stringdtype_null_is_truthy(const PyArray_StringDTypeObject *descr) | ||
| { | ||
| // nulls cannot be stored in an array without an na object | ||
| assert(descr->na_object != NULL); |
Contributor
There was a problem hiding this comment.
much better guard than has_null &&, nice!
ngoldbaum
added a commit
to ngoldbaum/numpy
that referenced
this pull request
Sep 8, 2026
ngoldbaum
added a commit
to ngoldbaum/numpy
that referenced
this pull request
Sep 8, 2026
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.
PR summary
Both nonzero and the string to bool cast incorrectly handled string missing data. The former is missing a case for
has_string_na: all the logic in the!has_string_nabranch, so string missing data falls through to the size check below, which always returns False. The latter gets the boolean condition inverted: thedefault_stringis falsey if it's empty.Even though these are logic errors, since this is changing the
nonzerotests I'm not marking this as a backport.AI Disclosure
An AI model spotted this bug and I used an AI for code review.