Skip to content

BUG: don't assume strides are a multiple of itemsize in stringdtype casts (#32273) - #32292

Merged
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-32273
Aug 14, 2026
Merged

BUG: don't assume strides are a multiple of itemsize in stringdtype casts (#32273)#32292
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-32273

Conversation

@charris

@charris charris commented Aug 14, 2026

Copy link
Copy Markdown
Member

Backport of #32273.

PR summary

See the test I added. On NumPy 2.5.2 you can get a cast to generate garbage by casting from void to StringDType:

>>> rec = np.zeros(3, dtype=[("c", "c16"), ("f", "f8")])
... rec["c"] = [1 + 1j, 2 + 2j, 3 + 3j]
... rec["f"] = [10.0, 20.0, 30.0]
...
>>> rec["c"].astype("T")
array(['(1+1j)', '(10+2j)', '(2+20j)'], dtype=StringDType())
>>> rec["c"]
array([1.+1.j, 2.+2.j, 3.+3.j])
>>> np.__version__
'2.5.2'

AI Disclosure

An AI model spotted this bug and helped me with the test case.

@charris charris added this to the 2.5.3 release milestone Aug 14, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Aug 14, 2026
@charris
charris merged commit cf919f2 into numpy:maintenance/2.5.x Aug 14, 2026
88 of 90 checks passed
@charris
charris deleted the backport-32273 branch August 14, 2026 23:21
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants