#12564·dask

Dask left merge carries over wrong index values in the presence of empty partitions

Author: albarjiCreated Aug 19, 2026Updated Sep 28, 2026
Labelsneeds attentionneeds triage

Describe the issue:

When using Dask left-merge with a right dataframe that contains empty partitions, the resultant dataframe is indexed by the index of the right dataframe, but some unmatched rows can use instead the index of the left dataframe. This inconsistent behavior is undesirable, as it can easily break the computation graph if following operations that expect the merged dataframe to be indexed by a common index.

Minimal Complete Verifiable Example:

(jointly developed with ramonruiz97)

python
import dask.dataframe as dd
import pandas as pd

from dask import delayed

left = dd.from_delayed(
    [
        delayed(pd.DataFrame(index=["A"])),
        delayed(pd.DataFrame(index=["B", "C"])),
    ],
    divisions=('A', 'B', 'C'),
    meta=pd.DataFrame(index=pd.Index([], dtype=str))
)
print(f"---left---\n{left.compute()}\n")

empty_partition = pd.DataFrame(data={"id": pd.Series([], dtype=str), "value": pd.Series([], dtype=int)}, index=pd.Index([], dtype=str))
right = dd.from_delayed(
    [
        delayed(empty_partition),
        delayed(empty_partition),
        delayed(pd.DataFrame(data={"id": ["A"], "value": [1]}, index=["AAA"])),
        delayed(pd.DataFrame(data={"id": ["B"], "value": [2]}, index=["BBB"])),
    ],
    # Unknown divisions
    meta=empty_partition
)
print(f"---right---\n{right.compute()}\n")

merged = left.merge(right, how="left", left_index=True, right_on="id")
print(f"---merged---\n{merged.compute()}\n")
Output
---left---
Empty DataFrame
Columns: []
Index: [A, B, C]

---right---
    id  value
AAA  A      1
BBB  B      2

---merged---
    id  value
AAA  A    1.0
BBB  B    2.0
C    C    NaN

The last row of the merge dataframe shows how the index is incorrectly taken from the left dataframe, although the rest of rows use the index of the right dataframe.

Anything else we need to know?:

Environment:

  • Dask version: 2026.6.0 and 2026.7.1
  • Python version: 3.12.13
  • Operating System: Ubuntu 26.04 LTS
  • Install method (conda, pip, source): pip