Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add support for nan-like null strings in string replace #26374

Merged
merged 1 commit into from May 6, 2024

Conversation

charris
Copy link
Member

@charris charris commented May 2, 2024

Backport of #26355.

This fixes an issue similar to the one fixed by #26353.

In particular, right now np.strings.replace calls the count ufunc to get the number of replacements. This is necessary for fixed-width strings, but it turns out to make it impossible to support null strings in replace.

I went ahead and instead found the replacement counts inline in the ufunc loop. This lets me add support for nan-like null strings, which it turns out pandas needs.

…6355)

This fixes an issue similar to the one fixed by numpy#26353.

In particular, right now np.strings.replace calls the count ufunc to get the number of replacements. This is necessary for fixed-width strings, but it turns out to make it impossible to support null strings in replace.

I went ahead and instead found the replacement counts inline in the ufunc loop. This lets me add support for nan-like null strings, which it turns out pandas needs.
@charris charris added 01 - Enhancement 08 - Backport Used to tag backport PRs labels May 2, 2024
@charris charris added this to the 2.0.0 release milestone May 2, 2024
@charris
Copy link
Member Author

charris commented May 2, 2024

@ngoldbaum Please check. Note that this adds zfill, that was not previously in 2.0.0.

@charris charris changed the title ENH: add support for nan-like null strings in string replace (#26355) ENH: add support for nan-like null strings in string replace May 2, 2024
@charris charris merged commit 885ffc1 into numpy:maintenance/2.0.x May 6, 2024
60 checks passed
@charris charris deleted the backport-26355 branch May 6, 2024 21:41
@ngoldbaum
Copy link
Member

@charris sorry, I missed the ping about this. The "zfill" test addition doesn't hurt anything, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants