#12604·dask

`set_index` splits duplicate index values across partitions when a list column is present and `repartition(partition_size=...)` precedes it (regression 2025.3.0 → 2025.4.1)

Author: guozhansCreated Sep 23, 2026Updated Sep 23, 2026
Labelsneeds triage

Describe the issue:

After set_index, all rows sharing an index value are expected to land in the same partition (divisions are non-overlapping), which makes the common set_index(...).map_partitions(lambda d: d.groupby(level=0)...) aggregation pattern safe.

Since dask 2025.4.1 this no longer holds for the pipeline below: most duplicate keys end up straddling two partitions, so per-partition groupbys silently emit two partial groups per key. The resulting partitions also appear to retain the input row order rather than being globally sorted by the new index, as if the shuffle was planned away.

The regression needs a combination of ingredients (removing any one of them makes it behave):

  • a column with nested data (list<struct> read from parquet, object dtype) that merely travels along,
  • repartition(partition_size=...) before set_index,
  • the index column derived via map_partitions (or a parquet round-trip),
  • dataframe.convert-string: False.

It reproduces with the local threaded scheduler — no distributed involved.

Minimal Complete Verifiable Example:

python
import os
import shutil
import tempfile

import pandas as pd
import pyarrow as pa

import dask
import dask.dataframe as dd

dask.config.set({"dataframe.convert-string": False})

# every even key appears twice, the two copies far apart in row order;
# 'members' is a list<struct> column that just travels along
n = 3_000
rows = []
for i in range(n):
    key = str(10_000_000_000 + i)
    for copy in range(2 if i % 2 == 0 else 1):
        rows.append(
            {
                "raw": f"prefix:{key}",
                "members": [{"role": "x", "id": key}],
                "sort": i + copy * 1_000_000,
            }
        )
df = pd.DataFrame(rows).sort_values("sort").drop(columns=["sort"]).reset_index(drop=True)

src = os.path.join(tempfile.gettempdir(), "dask_setindex_repro_src")
shutil.rmtree(src, ignore_errors=True)
schema = pa.schema(
    [
        ("raw", pa.string()),
        ("members", pa.list_(pa.struct([("role", pa.string()), ("id", pa.string())]))),
    ]
)
dd.from_pandas(df, npartitions=4).to_parquet(src, write_index=False, schema=schema)

ddf = dd.read_parquet(src, ignore_metadata_file=True)
ddf["key"] = ddf.map_partitions(
    lambda d: d["raw"].apply(lambda s: s.split(":")[1]), meta=(None, "object")
)
ddf = (
    ddf.repartition(partition_size="1MB")
    .astype({"key": "string"})
    .set_index("key")
)

# if divisions are honoured, each key lives in exactly one partition
per_partition = ddf.map_partitions(
    lambda d: d.groupby(level=0).size().rename("cnt").reset_index(),
    meta={"key": "string", "cnt": "int64"},
).compute()
spread = per_partition.groupby("key")["cnt"].count()
split = spread[spread > 1]
print(f"dask {dask.__version__}: {len(split)} of {n // 2} duplicate keys split across partitions")
assert len(split) == 0, f"e.g. {split.head(3).to_dict()}"

Output on 2025.3.0:

dask 2025.3.0: 0 of 1500 duplicate keys split across partitions

Output on 2025.4.1 / 2025.5.1 / 2025.7.0 / 2025.9.1 / 2025.12.0:

dask 2025.12.0: 1125 of 1500 duplicate keys split across partitions
AssertionError: e.g. {'10000000750': 2, '10000000752': 2, '10000000754': 2}

Anything else we need to know?:

Found in a production geospatial ETL: a set_index(id).map_partitions(groupby(level=0).apply(...)) aggregation started emitting duplicate output records for ids whose rows were split, i.e. silently wrong results. The same split also happens under distributed.Client.

Environment:

  • Dask version: regression window 2025.3.0 (good) → 2025.4.1 (bad); still present in 2025.12.0
  • Python version: 3.12
  • Operating System: macOS 15 arm64 and Ubuntu 24.04 x86_64 (Docker)
  • Install method: pip (pandas 2.2.3, pyarrow 23.0.1)
  • Scheduler: local threads (also reproduces with distributed LocalCluster)