Skip to content
Merged
Changes from 1 commit
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
16 changes: 12 additions & 4 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,9 @@ def group_last(rank_t[:, :] out,

assert min_count == -1, "'min_count' only used in add and prod"

if not len(values) == len(labels):
# NOTE:
# Casting to avoid build warnings
if not len(values) == <Py_ssize_t>len(labels):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to get the same result without casting? Maybe labels.shape[0] for memory views?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd It works!


Just so I know for future times, are we trying to avoid casting?

or casting is not possible with memory views?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If there's an easily available approach that doesn't require casting then should almost always go that route

raise AssertionError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
Expand Down Expand Up @@ -960,7 +962,9 @@ def group_nth(rank_t[:, :] out,

assert min_count == -1, "'min_count' only used in add and prod"

if not len(values) == len(labels):
# NOTE:
# Casting to avoid build warnings
if not len(values) == <Py_ssize_t>len(labels):
raise AssertionError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
Expand Down Expand Up @@ -1254,7 +1258,9 @@ def group_max(groupby_t[:, :] out,

assert min_count == -1, "'min_count' only used in add and prod"

if not len(values) == len(labels):
# NOTE:
# Casting to avoid build warnings
if not len(values) == <Py_ssize_t>len(labels):
raise AssertionError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
Expand Down Expand Up @@ -1327,7 +1333,9 @@ def group_min(groupby_t[:, :] out,

assert min_count == -1, "'min_count' only used in add and prod"

if not len(values) == len(labels):
# NOTE:
# Casting to avoid build warnings
if not len(values) == <Py_ssize_t>len(labels):
raise AssertionError("len(index) != len(labels)")

nobs = np.zeros((<object>out).shape, dtype=np.int64)
Expand Down