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 — BUG: centralized helper for output coerce and na_object in stringdtype operations by ngoldbaum · Pull Request #31884 · numpy/numpy

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Jul 6, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

PR summary

Related to #31825 but issuing it as a separate PR because the two changes don't overlap at all.

We currently have custom logic for determining the correct na_object and coerce value when operations mix StringDType instances. In some cases this can even lead to crashes. The following script segfaults for me because the na_object in the fill character array is not being handled correctly.

Python 3.14.5 (main, May 22 2026, 08:10:06) [Clang 21.0.0 (clang-2100.0.123.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from numpy.dtypes import StringDType
>>> print(np.__version__)
2.5.1
>>> arr = np.array(["a"], dtype="T")
>>> fill = np.array("*", dtype=StringDType(na_object="*"))
>>> print(np.strings.center(arr, 5, fill))
[1]    87011 segmentation fault  python

This centralizes the logic for handling the na_object and coerce argument in ufunc loops and in the comparison machinery into one set of shared helpers.

Also adds tests for this behavior, including the case that leads to a crash above.

First time committer introduction

AI Disclosure

I found this issue using an AI model. I also used an AI model to help with the tests and the approach for the fix.

Sorry, something went wrong.

Uh oh!

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

All reactions
@ngoldbaum ngoldbaum added this to the 2.5.2 release milestone Jul 6, 2026
@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported component: numpy.strings String dtypes and functions labels Jul 6, 2026
@ngoldbaum
BUG: centralize handling of operand order in stringdtype operations
2f6a487
@ngoldbaum
ngoldbaum force-pushed the nan-coerce-consistency branch from 0ce76e4 to 2f6a487 Compare July 6, 2026 19:57
@ngoldbaum

ngoldbaum commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@mhvk hope you don't mind a ping to look this over. #31825 as well if you have the bandwidth 🙈.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ngoldbaum ngoldbaum changed the title BUG: centralize handling of operand order in stringdtype operations BUG: centralized helper for output coerce and na_object in stringdtype operations Jul 6, 2026
@ngoldbaum

ngoldbaum commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@Ethan0456 you just put in a PR for a similar issue. Maybe you want to take a look at this?

Ethan0456 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@Ethan0456

Ethan0456 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@ngoldbaum LGTM! thanks for the clear repro. I reproduced the center segfault on 2.5.1; fixed on this branch with ['**a**']. The shared helpers match the intended rules, and scoping resolve to nin avoids walking NULL outs on ops like center. New mixed-instance tests look right and passed locally.

All reactions

Sorry, something went wrong.

Uh oh!

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

@charris
charris merged commit e4b464d into numpy:main Jul 8, 2026
85 checks passed

Uh oh!

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

@charris

charris commented Jul 8, 2026

Copy link
Copy Markdown
Member

Thanks Nathan.

All reactions

Sorry, something went wrong.

Uh oh!

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

@charris charris mentioned this pull request Jul 10, 2026
BUG: centralized helper for output coerce and na_object in stringdtype operations (#31884) #31952
Merged
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 10, 2026
charris pushed a commit that referenced this pull request Jul 10, 2026
@ngoldbaum @charris
BUG: centralized helper for output coerce and na_object in stringdtyp…
bdb1888
…e operations (#31884)
charris added a commit that referenced this pull request Jul 10, 2026
@charris
Merge pull request #31952 from charris/backport-31884
bb246e0
BUG: centralized helper for output coerce and na_object in stringdtype operations (#31884)
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Aug 4, 2026
@ngoldbaum
BUG: centralized helper for output coerce and na_object in stringdtyp…
53ffc39
…e operations (numpy#31884)

(cherry picked from commit e4b464d)
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Sep 8, 2026
@ngoldbaum
BUG: centralized helper for output coerce and na_object in stringdtyp…
993cb9a
…e operations (numpy#31884)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

2.5.2 release

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 @Ethan0456 @charris
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.