dask icon indicating copy to clipboard operation
dask copied to clipboard

fix: str.split coerces PyArrow string dtype to object

Open sridhar-3009 opened this issue 6 months ago • 1 comments

Problem

dask_df["col"].str.split(",", n=1, expand=True) on a PyArrow-backed string column (string[pyarrow]) returns columns with object dtype, diverging from pandas which preserves the original dtype.

Root cause

SplitMap._meta builds a synthetic meta series using self.frame._meta._constructor([...]) without specifying dtype. The constructor defaults to object for the string values, so the split result also uses object, and that incorrect meta propagates through the graph.

Fix

Pass dtype=self.frame._meta.dtype to the constructor so the meta series matches the dtype of the original column.

# before
meta = self.frame._meta._constructor(
    [delimiter.join(["a"] * (self.n + 1))],
    index=meta.iloc[:1].index,
)

# after
meta = self.frame._meta._constructor(
    [delimiter.join(["a"] * (self.n + 1))],
    index=meta.iloc[:1].index,
    dtype=self.frame._meta.dtype,
)

Test

test_str_split_preserves_dtype verifies that dtypes on the dask result match pandas for string[pyarrow] input.

Fixes #11884

sridhar-3009 avatar May 31 '26 08:05 sridhar-3009

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 50m 37s ⏱️ - 27m 52s  18 637 tests + 1   17 447 ✅ + 1   1 190 💤 ±0  0 ❌ ±0  378 927 runs  +20  331 661 ✅ +22  47 266 💤  - 2  0 ❌ ±0 

Results for commit 7ac5c74b. ± Comparison against base commit b3f266a4.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar May 31 '26 09:05 github-actions[bot]