Skip to content

BUG: fix StringDType distinct-allocator bugs and add tests (#31609) - #31703

Merged
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31609
Jun 20, 2026
Merged

charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31609

Conversation

@charris

@charris charris commented Jun 20, 2026

Copy link
Copy Markdown
Member

Backport of #31609.

Fixes bugs when multiple distinct stringdtype arrays are passed to np.choose, np.put, np.putmask, np.place, flatiter reads, and a bug that could lead to unsafe views being created for StringDType and object arrays.

Also exposes a new C helper function _is_safe_view_cast which takes view_offset into account and uses it in the Python helper functions for view safety. It only uses this function for StringDType. We could use it more generally but that might lead to breakage, so just fixing StringDType seemed like a practical first pass.

The C changes all work out to fixing the same couple patterns: legacy paths that used copyswap (e.g. #24859, which this might obviate the need for?) or code paths that assumed all input arrays have the same descriptor instance.

Also adds tests for functionality that is fixed here or is poorly tested currently. It makes use of a new helper function that allocates two distinct arrays of strings with allocations that live in the arena buffer to trigger these bugs.

I milestoned this for 2.5.0 and marked it for backport because these are all bugs that can cause segfaults.

I used Claude Fable 5 to work on this, including for the implementation and new tests.

@charris charris added this to the 2.5.0 Release milestone Jun 20, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs component: numpy.strings String dtypes and functions labels Jun 20, 2026
@charris
charris merged commit ce17c81 into numpy:maintenance/2.5.x Jun 20, 2026
83 of 85 checks passed
@charris
charris deleted the backport-31609 branch June 20, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs component: numpy.strings String dtypes and functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants