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(string dtype): Implement cumsum for Python-backed strings #60938

Merged
merged 9 commits into from
Feb 19, 2025

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Feb 15, 2025

Follow-up on #60633

@jorisvandenbossche jorisvandenbossche added this to the 2.3 milestone Feb 17, 2025
@jorisvandenbossche jorisvandenbossche added the Strings String extension data type and string data label Feb 17, 2025
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

# We can retain the running min/max by forward/backward filling.
ndarray = ndarray.copy()
missing.pad_or_backfill_inplace(
ndarray.T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the .T needed? (I would think that ndarray is 1D)

# the first NA value onward.
idx = np.argmax(na_mask)
tail = np.empty(len(ndarray) - idx, dtype="object")
tail[:] = np.nan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tail[:] = np.nan
tail[:] = self.dtype.na_value

So we directly fill it with the appropriate NA value (although I assume the constructor would fix it up anyway)

if tail is not None:
np_result = np.hstack((np_result, tail))
elif na_mask is not None:
np_result = np.where(na_mask, np.nan, np_result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
np_result = np.where(na_mask, np.nan, np_result)
np_result = np.where(na_mask, self.dtype.na_value, np_result)

@mroeschke mroeschke merged commit 4e20195 into pandas-dev:main Feb 19, 2025
42 checks passed
@mroeschke
Copy link
Member

Thanks @rhshadrach

Copy link

lumberbot-app bot commented Feb 19, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.3.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 4e20195086e5cdd5bde56da7d95cf672b795b32e
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #60938: ENH(string dtype): Implement cumsum for Python-backed strings'
  1. Push to a named branch:
git push YOURFORK 2.3.x:auto-backport-of-pr-60938-on-2.3.x
  1. Create a PR against branch 2.3.x, I would have named this PR:

"Backport PR #60938 on branch 2.3.x (ENH(string dtype): Implement cumsum for Python-backed strings)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Still Needs Manual Backport Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants