Skip to content

PERF: avoid zeros_like in groupby.pyx #40194

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ def _group_add(complexfloating_t[:, :] out,
raise ValueError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
sumx = np.zeros_like(out)
compensation = np.zeros_like(out)
# the below is equivalent to `np.zeros_like(out)` but faster
sumx = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)
compensation = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)

N, K = (<object>values).shape

Expand Down Expand Up @@ -555,7 +556,7 @@ def _group_prod(floating[:, :] out,
raise ValueError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
prodx = np.ones_like(out)
prodx = np.ones((<object>out).shape, dtype=(<object>out).base.dtype)

N, K = (<object>values).shape

Expand Down Expand Up @@ -608,7 +609,7 @@ def _group_var(floating[:, :] out,
raise ValueError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
mean = np.zeros_like(out)
mean = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)

N, K = (<object>values).shape

Expand Down Expand Up @@ -665,8 +666,9 @@ def _group_mean(floating[:, :] out,
raise ValueError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
sumx = np.zeros_like(out)
compensation = np.zeros_like(out)
# the below is equivalent to `np.zeros_like(out)` but faster
sumx = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)
compensation = np.zeros((<object>out).shape, dtype=(<object>out).base.dtype)

N, K = (<object>values).shape

Expand Down