Repository navigation
Description
Describe the issue:
I made a demo project that reproduces the silent row drop issue with left merge. Feel free to check it out. Thanks!
The issue occurs when the local cluster uses more than 128 partitions. Thanks!
Minimal Complete Verifiable Example:
Anything else we need to know?:
Environment:
dask[dataframe,distributed]>=2024.1.0
pandas>=2.0.0
pyarrow>=14.0.0
OS : WINDOWS
Suggested fixes:
Primary (dask): In create_assign_index_merge_transfer() (and similar shuffle transfer paths), if the join key selection is a single-column DataFrame, squeeze to a Series before partitioning_index(), so hashing matches on="POL_ID" semantics.
index = _select_columns_or_index(df, index)
if isinstance(index, pd.DataFrame) and index.shape[1] == 1:
index = index.iloc[:, 0]
Primary (dask): In partitioning_index(), do not use int8 when npartitions > 128 (e.g. use int16 or always int32 for the partition column), so bucket 128 is not stored as -128.
def partitioning_index(df, npartitions, cast_dtype=None):
"""
Computes a deterministic index mapping each record to a partition.
Identical rows are mapped to the same partition.
Parameters
----------
df : DataFrame/Series/Index
npartitions : int
The number of partitions to group into.
cast_dtype : dtype, optional
The dtype to cast to to avoid nullability issues
Returns
-------
partitions : ndarray
An array of int64 values mapping each record to a partition.
"""
if cast_dtype is not None:
# Fixme: astype raises with strings in numeric columns, but raising
# here might be very noisy
df = df.astype(cast_dtype, errors="ignore")
# print(f'df: {df}')
res = hash_object_dispatch(df, index=False) % int(npartitions)
# print(f'res: {res}')
# Note: Use a signed integer since pandas is more efficient at handling
# this since there is not always a fastpath for uints
# type_target = np.min_scalar_type(-(npartitions - 1))
# print(f'type_target: {type_target}')
# res2 = res.astype(type_target)
# print(f'res2: {res2}')
# return res2
if npartitions <= np.iinfo(np.int8).max + 1: # 129 > 128
dtype = np.int8
elif npartitions <= np.iinfo(np.int16).max + 1:
dtype = np.int16
else:
dtype = np.int32
return res.astype(dtype)Defense in depth (distributed): In split_by_worker(), avoid silently dropping rows when __hash_partition does not match worker_for.index (normalize partition ids and/or warn/raise instead of how="inner" data loss).
Tests to add:
partitioning_index(Series) == partitioning_index(single_col_DataFrame) for string keys
E2E: left.merge(..., shuffle_method="p2p") with npartitions=129 preserves all left rows, including left-only keys hashing to bucket 128
Related code paths:
dask/dataframe/dask_expr/_merge.py — HashJoinP2P._layer(), create_assign_index_merge_transfer()
dask/dataframe/dask_expr/_shuffle.py — _select_columns_or_index()
dask/dataframe/shuffle.py — partitioning_index()
distributed/shuffle/_shuffle.py — split_by_worker()
distributed/shuffle/_merge.py — merge_unpack()
Activity
crusaderky commentedon May 29, 2026
Could you come up with a shorter reproducer?
Also, does the issue disappear if you don't use LocalCluster (thus switch from p2p to disk shuffle)? What happens if you force
shuffle=tasks?[-]When a localcluster has more than 128 partitions, merging causes data loss without any warning. Caused by partitioning_index.[/-][+]`Dataframe.merge` loses data when there are more than 128 partitions[/+]hebian1994 commentedon May 29, 2026
@crusaderky
i create a short demo code , thanks
switch from p2p to disk shuffle: will report error : OverflowError: Python integer 129 out of bounds for int8