-
Notifications
You must be signed in to change notification settings - Fork 889
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
Fix groupby head/tail for empty dataframe #13398
Fix groupby head/tail for empty dataframe #13398
Conversation
@@ -678,7 +678,7 @@ def _head_tail(self, n, *, take_head: bool, preserve_order: bool): | |||
# subsample the gather map from the full input ordering, | |||
# rather than permuting the gather map of the output. | |||
_, (ordering,), _ = self._groupby.groups( | |||
[arange(0, self.obj._data.nrows)] | |||
[arange(0, len(self.obj))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same error occurs (previously and after the fix for scans in #13389, which was me again sorry!). Although it's impossible to reach that code path right now because mimic pandas order for scans only happens if the dataframe is not empty.
But can you apply this patch too please?
diff --git a/python/cudf/cudf/core/groupby/groupby.py b/python/cudf/cudf/core/groupby/groupby.py
index fb242a49ad..b3be6d9de0 100644
--- a/python/cudf/cudf/core/groupby/groupby.py
+++ b/python/cudf/cudf/core/groupby/groupby.py
@@ -2277,9 +2277,7 @@ class GroupBy(Serializable, Reducible, Scannable):
# result coming back from libcudf has null_count few rows than
# the input, so we must produce an ordering from the full
# input range.
- _, (ordering,), _ = self._groupby.groups(
- [arange(0, self.obj._data.nrows)]
- )
+ _, (ordering,), _ = self._groupby.groups([arange(0, len(self.obj))])
if self._dropna and any(
c.has_nulls(include_nan=True) > 0
for c in self.grouping._key_columns
@@ -2287,7 +2285,7 @@ class GroupBy(Serializable, Reducible, Scannable):
# Scan aggregations with null/nan keys put nulls in the
# corresponding output rows in pandas, to do that here
# expand the result by reindexing.
- ri = cudf.RangeIndex(0, self.obj._data.nrows)
+ ri = cudf.RangeIndex(0, len(self.obj))
result.index = cudf.Index(ordering)
# This reorders and expands
result = result.reindex(ri)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/merge |
Description
Closes #13397
Checklist