Skip to content

BUG: fix StringDType coerce flag in binary ufunc promotion (#31862) - #31901

Merged
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31862
Jul 7, 2026
Merged

BUG: fix StringDType coerce flag in binary ufunc promotion (#31862)#31901
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-31862

Conversation

@charris

@charris charris commented Jul 7, 2026

Copy link
Copy Markdown
Member

Backport or #31862.

PR summary

Fixes #31861.

Binary StringDType ufuncs resolved output coerce with descr1->coerce && descr1->coerce instead of combining both operands.

That made results order-dependent (e.g. np.add with coerce=True then coerce=False kept coerce=True) and allowed non-string assignment via implicit stringification.

This changes the combination to descr1->coerce && descr2->coerce, matching common_instance / np.promote_types, and adds a small regression test for both operand orders.

First time committer introduction

I have been using NumPy for some time now. I hit this while working with StringDType and coerce, and found two places with similar typo bug. I checked and found that one typo in common_instance has been fixed yesterday, so wanted to fix the remaining typo in the binary ufunc path.

AI Disclosure

I used Grok to help locate the bug in binary_resolve_descriptors, draft the regression test, and refine the issue/PR wording. I made and verified the fix with correctness checks, rebuilds and the test suite; final review and PR submission were done by me.

@charris charris added this to the 2.5.2 release milestone Jul 7, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs component: numpy.strings String dtypes and functions labels Jul 7, 2026
@charris
charris merged commit 8b1998e into numpy:maintenance/2.5.x Jul 7, 2026
86 checks passed
@charris
charris deleted the backport-31862 branch July 7, 2026 20:15
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