Skip to content

Fix Series.map(Series) producing wrong results for non-co-aligned inputs - #12432

Merged
crusaderky merged 9 commits into
dask:mainfrom
xronocode:fix/series-map-dtype-12426
Jun 1, 2026
Merged

crusaderky merged 9 commits into
dask:mainfrom
xronocode:fix/series-map-dtype-12426

Conversation

@xronocode

Copy link
Copy Markdown
Contributor

Summary

Fixes #12426. Series.map(dask_series) produced NaN values and wrong
dtypes when base and mapper had different partitioning.

Root cause: two bugs in the MapAlign / Map expression classes:

  1. MapAlign._parameters had a vestigial op field that shifted
    operand positions when lowering to Map — na_action and meta
    landed in wrong slots.

  2. MapAlign inherited MaybeAlignPartitions._lower() which
    index-aligns operands. But Series.map(Series) uses the mapper
    as a lookup table — every partition needs the full mapper, not
    an index-aligned slice.

Fix: MapAlign._lower() now repartitions the mapper to 1 partition
and passes it to Map directly, bypassing index alignment.
Map._broadcast_dep() broadcasts the single-partition mapper to all
frame partitions.

Test plan

  • Removed xfail markers from test_series_map_dtype_all_mapped,
    test_series_map_dtype_unmapped, test_series_map_dtype_null_base
    — all 22+22 variants now pass
  • Added targeted xfails for 24 pre-existing Index failures unrelated
    to this fix (nullable base dtype NA in divisions; float32+object/str
    dtype mismatch)
  • Added test_series_map_co_aligned_lookup (xfail) documenting
    the separate co-aligned path bug
  • test_map.py: 98 passed, 37 xfailed, 0 failed
  • test_dataframe.py: 602 passed, 0 failed (regression check)

xronocode added 2 commits May 31, 2026 18:39
The MapAlign fix (repartition mapper to 1 partition + broadcast)
handles base_npart != map_npart correctly. 12 more tests pass.
@github-actions

github-actions Bot commented May 31, 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  +     1       25 suites  +1   6h 55m 9s ⏱️ + 5m 5s
 18 635 tests +     1   17 445 ✅ +    92   1 190 💤  -  91  0 ❌ ±0 
378 883 runs  +18 453  331 621 ✅ +18 722  47 262 💤  - 269  0 ❌ ±0 

Results for commit 766ec3a. ± Comparison against base commit 55e016a.

♻️ This comment has been updated with latest results.

xronocode and others added 5 commits May 31, 2026 20:15
- black reformatted _expr.py (line-length) and test_map.py (conditionals)
- xfail test_series_map_dtype_unmapped[Index-values1-bool]: when all keys
  in a partition are unmapped, Index.map returns float64 (numpy NaN), but
  the overall result is object (mixed NaN + True). Per-partition dtype
  consistency check fails — this is a known pandas/dask interaction edge
  case, not a bug in our fix.
@crusaderky

crusaderky commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fix: MapAlign._lower() now repartitions the mapper to 1 partition

This is really not great for a user that abuses map() instead of using merge(). However, considering that this is outright broken in main, I'm going to merge it as is and leave a shuffle-based enhancement for the future.

@crusaderky
crusaderky merged commit 4131849 into dask:main Jun 1, 2026
33 checks passed
@crusaderky

Copy link
Copy Markdown
Collaborator

Thank you!

@xronocode
xronocode deleted the fix/series-map-dtype-12426 branch June 2, 2026 02:44
@crusaderky crusaderky mentioned this pull request Jun 5, 2026
1 task
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.

Series.map(func: Series) is broken in most cases

2 participants