[SPARK-56188][PS] Align Series.map({}) with pandas 3 empty-dict behavior#54991
Closed
ueshin wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-56188][PS] Align Series.map({}) with pandas 3 empty-dict behavior#54991ueshin wants to merge 1 commit intoapache:masterfrom
ueshin wants to merge 1 commit intoapache:masterfrom
Conversation
HyukjinKwon
approved these changes
Mar 24, 2026
Member
|
Merged to master for Apache Spark 4.2.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR updates pandas-on-Spark
Series.mapfor the pandas 3 case when the mapper is an empty plaindict.In pandas 3,
pandas.Series.map({})returns an all-NaNfloat64Series. pandas-on-Spark was preserving the input Spark string type for this path, so a string Series produced a pandasStringDtyperesult instead. This PR adds a pandas-3-only branch inpyspark.pandas.Series.mapsoSeries.map({})returns a nullDoubleTypecolumn for an empty plain dict, which materializes as the same all-NaNfloat64result as pandas.The related test was updated to check the pandas 3 expectation directly, while keeping the pre-pandas-3 expectation unchanged. The existing
defaultdictcoverage remains in place so dict subclasses with__missing__continue to follow the existing behavior. This patch also includes a small test adjustment so the local helper used intest_maponly uppercases string inputs.Why are the changes needed?
Without this change, pandas-on-Spark diverges from pandas 3 for
Series.map({}). For example, a string Series currently returns a pandasStringDtyperesult in pandas-on-Spark, while pandas returns an all-NaNfloat64Series.Aligning this narrow case avoids a pandas-version-specific mismatch in pandas-on-Spark behavior and keeps the test expectation consistent with pandas 3 internals.
Does this PR introduce any user-facing change?
Yes, it will behave more like pandas 3.
How was this patch tested?
Updated the related tests.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)