Skip to content

BUG: write bytes to canonical byteorder in StringDType casts - #32474

Merged
ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:stringdtype-byteorder-casts
Sep 2, 2026
Merged

ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:stringdtype-byteorder-casts

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

PR summary

Currently we're using the exact output descriptor for casts from string to types that support byte ordering. That's wrong and leads to incorrect answers when casting to an explicitly byteswapped dtype instance. See the new tests, which all fail with incorrect answers on main.

AI Disclosure

An AI spotted the bug and I used an AI to review the fix.

@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported component: numpy.strings String dtypes and functions labels Sep 1, 2026

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch by the AI, and the fix looks right: the loop descriptors should describe what the loop actually expects.

@ngoldbaum

Copy link
Copy Markdown
Member Author

I'm pretty sure the docs build failures are unrelated (scipy/docs.scipy.org#102). Thanks for the review @mhvk!

@ngoldbaum
ngoldbaum merged commit b58ff8d into numpy:main Sep 2, 2026
90 of 92 checks passed
@charris

charris commented Sep 2, 2026

Copy link
Copy Markdown
Member

@ngoldbaum I note that all the string tests are new, none of them are in 2.5.x. That makes me wonder about the backport.

@ngoldbaum

Copy link
Copy Markdown
Member Author

This bug has existed since NumPy 2.0. If you feel like a fix for NumPy writing garbage output isn't backportable that's your call though.

@charris

charris commented Sep 2, 2026

Copy link
Copy Markdown
Member

The fix is fine, it is the tests I worry about, since they are all new and might depend on developments in main.

@ngoldbaum

Copy link
Copy Markdown
Member Author

@charris I see what you mean, there is also a related hunk in #31825 that needed to be backported as well. See #32481.

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug component: numpy.strings String dtypes and functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants