Skip to content

Pandas 3.1: tuple groupby keys are deprecated - #12713

Merged
crusaderky merged 2 commits into
dask:mainfrom
crusaderky:fix/pandas-groupby-tuple-getitem
Nov 12, 2026
Merged

crusaderky merged 2 commits into
dask:mainfrom
crusaderky:fix/pandas-groupby-tuple-getitem

Conversation

@crusaderky

@crusaderky crusaderky commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

pandas 3.1 deprecates passing a tuple to GroupBy.__getitem__:

Pandas4Warning: Passing a tuple to __getitem__ is deprecated and will raise a
KeyError in a future version. Use a list instead.

Dask used to swallow that deprecation. This PR changes it to let it flow through.

pandas 3.1 deprecates passing a tuple to GroupBy.__getitem__ and will raise
a KeyError in a future version. Compute the pandas expectation with a list
for tuple slice keys while keeping the dask collection call on the original
parameter, so dask's tuple support stays covered.
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     25 files  ± 0       25 suites  ±0   6h 59m 21s ⏱️ + 6m 43s
 19 916 tests + 2   18 483 ✅ + 3   1 433 💤 ±0  0 ❌  - 1 
379 393 runs  +40  332 120 ✅ +36  47 273 💤 +5  0 ❌  - 1 

Results for commit c79dce7. ± Comparison against base commit b4cc5c5.

♻️ This comment has been updated with latest results.

`GroupBy.__getitem__` eagerly converted tuple keys to lists before handing
them to pandas. That made `ddf.groupby("a")[("b", "c")]` return columns
where every supported pandas version raises `ValueError`, and it kept a
single-element tuple from ever producing the pandas>=3.1 `Pandas4Warning`.

Pass tuple keys through unchanged in the meta lookup and in `_apply_chunk`
so dask defers to pandas instead of diverging from it.

Tests: drop the list workaround from the pandas expectation, skip the
single-element tuple parity case on pandas>=3.1, expect pandas' ValueError
for multi-element tuples, and assert the deprecation warning surfaces.
@crusaderky crusaderky changed the title [unsupervised AI] Avoid deprecated tuple __getitem__ in groupby tests [unsupervised AI] Surface pandas deprecation of tuple groupby keys Nov 12, 2026
@crusaderky crusaderky changed the title [unsupervised AI] Surface pandas deprecation of tuple groupby keys Pandas 3.1: tuple groupby keys are deprecated Nov 12, 2026
@crusaderky
crusaderky marked this pull request as ready for review November 12, 2026 17:26
@crusaderky
crusaderky merged commit 42e1958 into dask:main Nov 12, 2026
31 of 34 checks passed
@crusaderky
crusaderky deleted the fix/pandas-groupby-tuple-getitem branch November 12, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant