Skip to content

Keep the dtype family in GroupBy.rank results - #23258

Merged
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
galipremsagar:groupby-rank-fixes
Jul 16, 2026
Merged

Keep the dtype family in GroupBy.rank results#23258
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
galipremsagar:groupby-rank-fixes

Conversation

@galipremsagar

Copy link
Copy Markdown
Contributor

Description

Running pandas' own test suite under cudf.pandas, tests/groupby/methods/test_rank.py had 4 failing tests (test_rank_avg_even_vals with masked integer dtypes). This PR fixes them (1548/1548 pass) and removes the corresponding xfail entries from the pandas-testing plugin.

pandas' groupby rank always returns floats within the value column's dtype family (verified on pandas 3.0.3):

input dtype rank result
int64 / float32 (numpy) float64
Int64 / Float32 (masked) Float64
int64[pyarrow] double[pyarrow]

cuDF's GroupBy.rank ended with a blanket cast to numpy float64, flattening masked inputs. Map each result column through the existing get_dtype_of_same_kind helper instead, which reproduces the table above for both SeriesGroupBy and DataFrameGroupBy results.

Validation: pandas-tests tests/groupby/methods/test_rank.py 1548/1548; the neighboring series/methods/test_rank.py and frame/methods/test_rank.py show only their pre-existing known failures; the cuDF classic groupby suite passes with a new parametrized regression test pinning the dtype-family table.

Checklist

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

pandas' groupby rank always returns floats within the value column's
dtype family: numpy dtypes give float64, masked dtypes give Float64
(Float32 included), and arrow dtypes give double[pyarrow]. cuDF's
blanket cast to numpy float64 flattened masked inputs; map each result
column through get_dtype_of_same_kind instead.

Fixes the 4 failing tests in pandas' tests/groupby/methods/test_rank.py
under cudf.pandas (1548/1548 pass) and removes their plugin entries.
@galipremsagar
galipremsagar requested a review from a team as a code owner July 14, 2026 14:04
@galipremsagar
galipremsagar requested review from rjzamora and wence- July 14, 2026 14:04
@copy-pr-bot

copy-pr-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added Python Affects Python cuDF API. cudf.pandas Issues specific to cudf.pandas labels Jul 14, 2026
@galipremsagar galipremsagar added bug Something isn't working non-breaking Non-breaking change labels Jul 14, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a0981419-e49d-4b21-952b-343655c8864b

📥 Commits

Reviewing files that changed from the base of the PR and between cc83313 and e460ba1.

📒 Files selected for processing (2)
  • python/cudf/cudf/core/groupby/groupby.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • python/cudf/cudf/core/groupby/groupby.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved groupby().rank() dtype post-processing to cast results into the appropriate float64-family/ masked numeric family based on the originating data.
    • Ensured ranking outputs match expected float64 vs pandas masked (Int64/Float32) representations.
  • Tests

    • Added a new dtype-family test for groupby().rank() to validate both dtype and computed values against pandas for NumPy and masked types.
    • Updated the testing plugin’s known-failures registry by removing resolved TODOs related to rank.

Walkthrough

GroupBy.rank now preserves compatible float dtype families for one-dimensional and multi-column results. Tests cover NumPy and pandas masked dtypes, and passing rank cases are removed from the known-failures registry.

Changes

GroupBy rank dtype preservation

Layer / File(s) Summary
Preserve dtype families in rank outputs
python/cudf/cudf/core/groupby/groupby.py
GroupBy.rank casts rank results to compatible float dtypes based on source or result column dtypes.
Validate rank dtype behavior
python/cudf/cudf/tests/groupby/test_rank.py, python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
Parametrized tests verify NumPy and pandas masked dtype outputs and pandas-equivalent ranks; rank known-failure entries are removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • rapidsai/cudf#23260: Updates known-failure entries for the same test_rank_avg_even_vals test while changing related groupby behavior.

Suggested reviewers: wence-, rjzamora

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving dtype family in GroupBy.rank results.
Description check ✅ Passed The description directly explains the rank dtype-family fix, test updates, and validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
python/cudf/cudf/tests/groupby/test_rank.py (1)

63-84: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Extend coverage to Arrow and 2D/as_index=False results.

This test only covers NumPy/masked dtypes with default as_index=True and one value column. Add cases for double[pyarrow], SeriesGroupBy, multi-column frames, and as_index=False with a string grouping key; include null-bearing inputs to validate nullable behavior.

As per coding guidelines, python/**/test_*.py should provide comprehensive edge-case coverage, including empty, all-null, single-element, and mixed-type inputs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/cudf/cudf/tests/groupby/test_rank.py` around lines 63 - 84, Expand
test_rank_dtype_family coverage to include double[pyarrow], SeriesGroupBy,
multi-column frames, and as_index=False with a string key. Add null-bearing,
empty, all-null, single-element, and mixed-type inputs while preserving
validation of nullable dtype behavior and pandas/cudf result equality.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cudf/cudf/core/groupby/groupby.py`:
- Around line 888-897: Update the dtype mapping in the result conversion around
GroupBy.agg so grouping-key columns are excluded when as_index=False. Apply
get_dtype_of_same_kind only to value columns, while preserving grouping-key
columns’ original dtypes and leaving the existing conversion behavior for
aggregated values unchanged.

---

Nitpick comments:
In `@python/cudf/cudf/tests/groupby/test_rank.py`:
- Around line 63-84: Expand test_rank_dtype_family coverage to include
double[pyarrow], SeriesGroupBy, multi-column frames, and as_index=False with a
string key. Add null-bearing, empty, all-null, single-element, and mixed-type
inputs while preserving validation of nullable dtype behavior and pandas/cudf
result equality.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1cd89ee0-438f-4d9d-85ce-361beaf7ce60

📥 Commits

Reviewing files that changed from the base of the PR and between 36366f8 and bc625c9.

📒 Files selected for processing (3)
  • python/cudf/cudf/core/groupby/groupby.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
  • python/cudf/cudf/tests/groupby/test_rank.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py

Comment thread python/cudf/cudf/core/groupby/groupby.py
@galipremsagar
galipremsagar requested a review from mroeschke July 15, 2026 13:39
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/okay to test d3994b1

Comment thread python/cudf/cudf/core/groupby/groupby.py Outdated
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/okay to test cc83313

@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label Jul 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cudf/cudf/core/groupby/groupby.py`:
- Line 2392: Update the UDF documentation URL in the groupby documentation
reference to use the official user_guide/guide-to-udfs/ path instead of
cudf/guide-to-udfs/, without changing the surrounding text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b509ec18-0c95-4380-9deb-5e68982186ca

📥 Commits

Reviewing files that changed from the base of the PR and between d3994b1 and cc83313.

📒 Files selected for processing (2)
  • python/cudf/cudf/core/groupby/groupby.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cudf/cudf/core/groupby/groupby.py`:
- Line 2392: Update the UDF documentation URL in the groupby documentation
reference to use the official user_guide/guide-to-udfs/ path instead of
cudf/guide-to-udfs/, without changing the surrounding text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b509ec18-0c95-4380-9deb-5e68982186ca

📥 Commits

Reviewing files that changed from the base of the PR and between d3994b1 and cc83313.

📒 Files selected for processing (2)
  • python/cudf/cudf/core/groupby/groupby.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
🛑 Comments failed to post (1)
python/cudf/cudf/core/groupby/groupby.py (1)

2392-2392: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the UDF guide link.

The link points to cudf/guide-to-udfs/, but the official page is under user_guide/guide-to-udfs/; update the path to avoid sending users to the wrong page. (docs.rapids.ai)

Proposed fix
-          <https://docs.rapids.ai/api/cudf/stable/cudf/guide-to-udfs/>`__.
+          <https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs/>`__.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

          <https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs/>`__.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/cudf/cudf/core/groupby/groupby.py` at line 2392, Update the UDF
documentation URL in the groupby documentation reference to use the official
user_guide/guide-to-udfs/ path instead of cudf/guide-to-udfs/, without changing
the surrounding text.

# Conflicts:
#	python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/okay to test e460ba1

@galipremsagar

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 2639194 into NVIDIA:main Jul 16, 2026
125 of 126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working cudf.pandas Issues specific to cudf.pandas non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants