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

Fix groupby head/tail for empty dataframe #13398

Merged
merged 3 commits into from
May 22, 2023

Conversation

shwina
Copy link
Contributor

@shwina shwina commented May 20, 2023

Description

Closes #13397

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@github-actions github-actions bot added the Python Affects Python cuDF API. label May 20, 2023
@@ -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))]
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@shwina shwina added bug Something isn't working non-breaking Non-breaking change labels May 22, 2023
@shwina shwina marked this pull request as ready for review May 22, 2023 16:28
@shwina shwina requested a review from a team as a code owner May 22, 2023 16:28
@shwina shwina requested review from bdice and charlesbluca May 22, 2023 16:28
@shwina
Copy link
Contributor Author

shwina commented May 22, 2023

/merge

@rapids-bot rapids-bot bot merged commit 9b1496d into rapidsai:branch-23.06 May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] groupby.head on an empty dataframe results in CUDA error
4 participants