Skip to content

Fix group-key columns in SeriesGroupBy list-agg and any/all with as_index=False - #22813

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
galipremsagar:gb_agg_1
Jun 15, 2026
Merged

rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
galipremsagar:gb_agg_1

Conversation

@galipremsagar

@galipremsagar galipremsagar commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes two bugs in SeriesGroupBy aggregations with as_index=False, where the group-key columns are materialized as output columns. Both only surfaced with categorical group keys, which is why they showed up in the cudf.pandas tests/groupby/test_categorical.py::test_agg_list cases.

  1. SeriesGroupBy.agg([func]) blanked the key-column name. A list aggregation produces a column MultiIndex; with as_index=False the key is inserted as a (key, "") tuple by reset_index. The result columns were collapsed with a blanket droplevel(0), which keeps the empty padding level and so renamed the key column to "" (e.g. ["a1", "var"] became ["", "var"]). It now keeps the key name for key columns and the aggregation name for value columns.

  2. any/all corrupted the categorical key column. _bool_reduce implements any/all as max/min on bool-coerced columns, then casts the results back to bool. With as_index=False that loop also ran over the key columns inserted into the result, turning e.g. a categorical key [0, 1] into [False, True]. It now skips the group-key columns when coercing to bool.

This un-xfails the previously-failing tests/groupby/test_categorical.py::test_agg_list[...] cases in the cudf.pandas pandas test suite (and incidentally fixes test_category_order_reducer). cuDF's own groupby test-suite shows no regressions.

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

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 Jun 9, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jun 9, 2026
@galipremsagar galipremsagar added bug Something isn't working 3 - Ready for Review Ready for review by team non-breaking Non-breaking change labels Jun 9, 2026
@galipremsagar galipremsagar changed the title fix Fix group-key columns in SeriesGroupBy list-agg and any/all with as_index=False Jun 9, 2026
@galipremsagar
galipremsagar marked this pull request as ready for review June 9, 2026 00:15
@galipremsagar
galipremsagar requested a review from a team as a code owner June 9, 2026 00:15
@coderabbitai

coderabbitai Bot commented Jun 9, 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: 85ba82d1-0f3d-4112-b21d-4f9fe312359b

📥 Commits

Reviewing files that changed from the base of the PR and between 71734d5 and bf2c84c.

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

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed groupby boolean reductions that could incorrectly cast group-key columns to boolean when keys were included in the result.
    • Improved multi-level column aggregation so grouping-key names are preserved correctly in aggregated results.
  • Tests

    • Removed an expected-failure entry for a categorical groupby aggregation test, reflecting updated test behavior.

Walkthrough

Prevents boolean coercion of grouping-key columns in DataFrame aggregation results and corrects MultiIndex-to-Index flattening for SeriesGroupBy. Updates pandas-testing expected-failure mappings to reflect the behavioral changes.

Changes

GroupBy Aggregation Fixes

Layer / File(s) Summary
Boolean reduction and MultiIndex column handling in aggregation
python/cudf/cudf/core/groupby/groupby.py
_bool_reduce now skips coercing columns matching group-key names to boolean when result is a DataFrame with as_index=False. SeriesGroupBy.agg rebuilds column index by preserving group-key names for padding entries where the second level is empty, otherwise uses the second-level label.
Test expectation updates for groupby aggregation
python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
Removes expected-failure block for tests/groupby/test_categorical.py::test_agg_list cases and updates nearby test_apply.py groupby test expectation entries to reflect aggregation logic fixes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • bdice
  • brandon-b-miller
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately describes the main fixes: addressing group-key column handling in SeriesGroupBy list-agg and any/all operations with as_index=False.
Description check ✅ Passed The pull request description provides clear explanations of both bugs fixed, their root causes, and the solutions implemented, with direct connection to the changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@galipremsagar

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 69ab110 into NVIDIA:main Jun 15, 2026
124 checks passed
@galipremsagar galipremsagar added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Jun 15, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jun 15, 2026
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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants