Repository navigation
MAINT: parse dtype endian as unicode directly (gh-15317) - #32353
Merged
ngoldbaum merged 3 commits intoAug 20, 2026
Merged
Conversation
nakasan617
force-pushed
the
maint-descriptor-endian-unicode
branch
from
August 19, 2026 21:43
4d5c852 to
5b30924
Compare
nakasan617
force-pushed
the
maint-descriptor-endian-unicode
branch
from
August 20, 2026 01:16
5b30924 to
fbdd0b9
Compare
nakasan617
marked this pull request as ready for review
August 20, 2026 03:20
ngoldbaum
reviewed
Aug 20, 2026
ngoldbaum
left a comment
Member
There was a problem hiding this comment.
A few comments, thanks for pushing on this!
nakasan617
marked this pull request as draft
August 20, 2026 19:48
Co-authored-by: Nathan Goldbaum <[email protected]>
Address review: PyUnicode_AsUTF8AndSize still raises UnicodeEncodeError for lone surrogates, so gate on PyUnicode_IS_ASCII and fall through to the existing "endian is not 1-char string" error instead. Also build the dtype inside test_setstate_endian so __setstate__ does not mutate an object shared between parametrized runs.
ngoldbaum
approved these changes
Aug 20, 2026
ngoldbaum
marked this pull request as ready for review
August 20, 2026 20:34
Member
|
Thanks @nakasan617! |
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.
Part of gh-15317, following #32232 (nditer flags) and #32305 (ndarray.flags keys).
(I realized that the issue is already closed, but I think we can still work on this one as the last one of the issue)
We are trying to replace PyUnicode_AsASCIIString which throws UnicodeEncodeError, but should rather be ValueError (or something that better describes the error in each context). This function also have a side effect of needing to allocate temporary memory for python string objects. In this pr, we're working on arraydescr_setstate, which looks into the byte order (e.g. little endian) when we are depickling (i.e. from byte to obj) and parses them . We change whenever the non ASCII is passed to give a ValueError instead of UnicodeEncodeError.
We added the tests to verify that it still reads the byte string correctly, throws the right error (i.e. ValueError) with correct error messages.
The release note will be bundled together for the same issue (with multiple PRs) as discussed in the previous PR.
AI Disclosure
Code, tests are AI-generated (Claude model Opus). PR summaries and comments are mine. I've looked into the code extensively, so I should know what's going on fully.