GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: add no-op fallback in np.byteswap for types with no byte order by ngoldbaum · Pull Request #32150 · numpy/numpy

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Jul 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR summary

This adds a no-op fallback for dtypes that declare no particular byte order ("|"). IMO this is a sensible default for these dtypes.

To make e.g. QuadDType work properly here we'll need to add an API hook that allows a user dtype to define a byteswapping operation. Punting on that for now.

AI Disclosure

I used an AI model to assist with debugging this change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ngoldbaum added 2 commits July 30, 2026 10:21
@ngoldbaum
BUG: fix aliasing issue for short strings
25f61bc
@ngoldbaum
ENH: add no-op fallback in np.byteswap for types with no byte order
18f6dfa
@ngoldbaum ngoldbaum added 01 - Enhancement component: numpy.dtype component: numpy.strings String dtypes and functions labels Jul 30, 2026
@ngoldbaum ngoldbaum mentioned this pull request Jul 30, 2026
BUG: avoid segfaults when legacy copyswap slot is not defined #32151
Merged
@ngoldbaum ngoldbaum added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jul 30, 2026
@ngoldbaum
ngoldbaum marked this pull request as draft July 31, 2026 15:57
@ngoldbaum

ngoldbaum commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

I marked this as draft because I want to do this after #32151 merges now. This PR will contain the "new" allowed behaviors, once we decide on them. I think only error make sense for a backport.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ngoldbaum added 4 commits August 6, 2026 15:42
@ngoldbaum
Merge branch 'main' into fix-byteswap-segfault
5bcb736
@ngoldbaum
ENH: make byteswapping operations a no-op for '|' byteorder dtypes
970a9b6
@ngoldbaum
MAINT: simplify
6c2a9a7
@ngoldbaum
DOC: add release note fragment
cf212c4
@ngoldbaum
ngoldbaum force-pushed the fix-byteswap-segfault branch from 27f32fd to cf212c4 Compare August 6, 2026 22:30
@ngoldbaum
ngoldbaum marked this pull request as ready for review August 6, 2026 22:31
@charris charris mentioned this pull request Aug 7, 2026
BUG: avoid segfaults when legacy copyswap slot is not defined (#32151) #32221
Merged
ikrommyd
ikrommyd reviewed Aug 8, 2026
View reviewed changes

@ikrommyd ikrommyd left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me overall. Got a release note change request + a suggestion to fix a pre-existing bug.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/release/upcoming_changes/32150.change.rst Outdated
Comment on lines +1 to +4
* ``ndarray.byteswap`` and ``numpy.byteswap`` now support dtypes that have no
defined byte order (e.g. when ``dtype.byteorder == "|"``). This includes NumPy's
string dtypes. Such values are left unchanged, including when they occur in
structured dtypes.

@ikrommyd ikrommyd Aug 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This needs a different format with a title right? + numpy.byteswap does not exist.

Suggested change
* ``ndarray.byteswap`` and ``numpy.byteswap`` now support dtypes that have no
defined byte order (e.g. when ``dtype.byteorder == "|"``). This includes NumPy's
string dtypes. Such values are left unchanged, including when they occur in
structured dtypes.
Byteswapping dtypes without a defined byte order is now supported as as no-op
-----------------------------------------------------------------------------
``ndarray.byteswap`` now supports dtypes that have no defined byte order
(e.g. when ``dtype.byteorder == "|"``). This includes NumPy's string dtypes.
Such values are left unchanged, including when they occur in structured dtypes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ngoldbaum ngoldbaum Aug 11, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This needs a different format with a title right?

You don't need to use a title, no. We also have all_bullets = false in our towncrier config:

numpy/pyproject.toml

Line 113 in 5799ed4

all_bullets = false

So if I explicitly add a bullet like this, it'll render as one of a number of bulleted bugfixes. I don't think this is worth a whole heading in the release notes, personally.

Thanks for catching my using the wrong name!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ikrommyd ikrommyd Aug 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ah I was not aware of the no-heading formatting. numpy.byteswap is the only valid comment then here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ngoldbaum ngoldbaum Aug 12, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

we should probably add some text about it to the README we have in the release notes folder.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ngoldbaum ngoldbaum Aug 12, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I also loosened the text about string dtypes here. Of course the UCS-4 unicode dtype is byteswappable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread numpy/_core/src/multiarray/scalartypes.c.src Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread numpy/_core/src/multiarray/scalartypes.c.src Resolved

Uh oh!

There was an error while loading. Please reload this page.

mhvk
mhvk reviewed Aug 8, 2026
View reviewed changes

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Had a decent go-over and this looks all fine (I would not have picked up on the VOID/etc asserts...).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ngoldbaum ngoldbaum mentioned this pull request Aug 11, 2026
BUG: avoid uninitialized memory access / NULL-pointer deref in scalar byteswap #32254
Merged
@ngoldbaum
Merge branch 'main' into fix-byteswap-segfault
99b6ffc
ikrommyd
ikrommyd reviewed Aug 12, 2026
View reviewed changes

@ikrommyd ikrommyd left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think only the numpy.byteswap thing on the release note comment is left here. Otherwise good to go from my side. CI needs to run though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ngoldbaum
DOC: fix up docstring
4f29908
ikrommyd
ikrommyd approved these changes Aug 12, 2026
View reviewed changes

@ikrommyd ikrommyd left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If CI is happy, I'm happy :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ngoldbaum ngoldbaum removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Aug 12, 2026
@ngoldbaum
ngoldbaum merged commit ea907a8 into numpy:main Aug 12, 2026
91 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ngoldbaum

ngoldbaum commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review all!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charris charris mentioned this pull request Aug 14, 2026
BUG: avoid uninitialized memory access / NULL-pointer deref in scalar byteswap (#32254) #32290
Merged
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Sep 8, 2026
@ngoldbaum
ENH: add no-op fallback in np.byteswap for types with no byte order (n…
557f04f
…umpy#32150)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mhvk mhvk mhvk left review comments
@ikrommyd ikrommyd ikrommyd approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

01 - Enhancement component: numpy.dtype component: numpy.strings String dtypes and functions

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@ngoldbaum @mhvk @ikrommyd
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.