Skip to content

MAINT: parse nditer flags as unicode directly (gh-15317) - #32232

Merged
ngoldbaum merged 5 commits into
numpy:mainfrom
nakasan617:maint-nditer-flags-unicode
Aug 13, 2026
Merged

ngoldbaum merged 5 commits into
numpy:mainfrom
nakasan617:maint-nditer-flags-unicode

Conversation

@nakasan617

@nakasan617 nakasan617 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

PR summary

Part of gh-15317 (cleaning up internal callers of PyUnicode_AsASCIIString).

NpyIter_GlobalFlagsConverter and NpyIter_OpFlagsConverter encoded unicode flag strings to bytes with PyUnicode_AsASCIIString before inspecting them. That allocates a throwaway bytes object for every flag, and for non-ASCII input it raises UnicodeEncodeError — which doesn't describe what the user actually did wrong. This should be a value error instead of Unicode Encode Error.

I created the test cases to raise ValueErrors when flags are not correct Unicode or not strings. I have also added the positive test cases when byte strings are passed as well.

First time committer introduction

Hello! My name is Yuta Nakamura, and I'm a backend software engineer. It made me curious how NumPy was created, and realized it was open source, and now it's easier than ever to contribute, so I decided to contribute to the project. I did a Ph.D. in computer science at DePaul University (in Chicago) specializing in program analysis. I'm originally from Japan but spent half of my life in the US.

AI Disclosure

I discussed the code with Claude to understand it and what changes need to be made, and I wrote the code myself to fix them. Tests are written by me (but discussed with claude where I should write and what I should write).

Comment thread numpy/_core/src/multiarray/nditer_pywrap.c
Comment thread numpy/_core/tests/test_nditer.py Outdated

@ngoldbaum ngoldbaum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the mac conda CI failure is unrelated but I also spotted some minor cleanups in the docstring.

Comment thread doc/release/upcoming_changes/32232.improvement.rst Outdated
Co-authored-by: Nathan Goldbaum <[email protected]>
@nakasan617

Copy link
Copy Markdown
Contributor Author

regards to the macos failure, it seems that it's due to trunk. ill rebase once that seems to be resolved.

@ngoldbaum

Copy link
Copy Markdown
Member

Thanks @nakasan617 and for your patience as well.

@ngoldbaum
ngoldbaum merged commit 1ec8d18 into numpy:main Aug 13, 2026
91 of 92 checks passed
@nakasan617
nakasan617 deleted the maint-nditer-flags-unicode branch August 15, 2026 17:19
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.

2 participants