Skip to content

BUG: fix fill value for gouped sum in case of unobserved categories for string dtype (empty string instead of 0) #61909

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jorisvandenbossche
Copy link
Member

I ran into one more case of the sum of empty / all-NaN to use "0" instead of empty string (#60229), specifically when effectively introducing empty groups with categorical data with observed=False.

Follow-up on #60936

The passing through of is_string through several layers is a bit annoying, but effectively is needed to for now only changes this for string dtype, and not for object dtype in general (which in the other PR related to this, we did for now)

@jorisvandenbossche jorisvandenbossche added this to the 2.3.2 milestone Jul 19, 2025
@jorisvandenbossche jorisvandenbossche added Bug Groupby Strings String extension data type and string data labels Jul 19, 2025
@@ -729,6 +730,10 @@ def group_sum(
sumx = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)
compensation = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)

if is_string:
# for strings start with empty string instead of 0 as `initial` value
sumx = np.full((<object>out).shape, "", dtype=object)
Copy link
Member

Choose a reason for hiding this comment

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

Would passing “initial” be more general/idiomatic?

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

Successfully merging this pull request may close these issues.

2 participants