Skip to content

MAINT: parse ndarray.flags keys as unicode directly (gh-15317) - #32305

Merged
ngoldbaum merged 1 commit into
numpy:mainfrom
nakasan617:maint-flagsobject-key-unicode
Aug 18, 2026
Merged

ngoldbaum merged 1 commit into
numpy:mainfrom
nakasan617:maint-flagsobject-key-unicode

Conversation

@nakasan617

@nakasan617 nakasan617 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

PR summary

This is one of the code that's trying to resolve numpy#15317 which is to take out the code as below

if (PyUnicode_Check(obj)) {
    PyObject *obj_bytes = PyUnicode_AsASCIIString(obj);   /* encode first */
    ...
}
PyBytes_AsStringAndSize(obj, &str, &length);              /* then work with bytes */

which is all over this repo. This is problematic as PyUnicode_AsASCIIString(obj); could throw UnicodeEncodeError, which does not describe the issue accurately. In this PR, I'm replacing one for the function getitem to have simply key errors instead of encoding errors. For the function setitem, it would have the exact same behavior, but we're removing the PyUnicode_AsASCIIString function in the code and simplifying the code.

AI Disclosure

Code, tests, and release notes 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.

@nakasan617
nakasan617 marked this pull request as draft August 15, 2026 19:29
@nakasan617 nakasan617 changed the title MAINT: parse ndarray.flags keys as unicode directly (gh-15317) [DRAFT] MAINT: parse ndarray.flags keys as unicode directly (gh-15317) Aug 15, 2026
@nakasan617
nakasan617 force-pushed the maint-flagsobject-key-unicode branch 2 times, most recently from e3a1d6c to 37f0fd7 Compare August 16, 2026 00:01
@nakasan617
nakasan617 marked this pull request as ready for review August 16, 2026 00:16
Comment thread doc/release/upcoming_changes/32305.improvement.rst Outdated
Comment thread numpy/_core/src/multiarray/flagsobject.c Outdated
@nakasan617
nakasan617 force-pushed the maint-flagsobject-key-unicode branch from 37f0fd7 to a5316cf Compare August 18, 2026 01:30
@nakasan617
nakasan617 marked this pull request as draft August 18, 2026 01:30
@nakasan617
nakasan617 marked this pull request as ready for review August 18, 2026 01:40
@ngoldbaum

Copy link
Copy Markdown
Member

Thank you!

@ngoldbaum
ngoldbaum merged commit 448054e into numpy:main Aug 18, 2026
111 of 118 checks passed
@nakasan617
nakasan617 deleted the maint-flagsobject-key-unicode branch August 18, 2026 18:57
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.

Clean up internal callers of PyUnicode_AsASCIIString

2 participants