[SPARK-43543][PYTHON] Fix nested MapType behavior in Pandas UDF#41147
Closed
xinrong-meng wants to merge 5 commits intoapache:masterfrom
Closed
[SPARK-43543][PYTHON] Fix nested MapType behavior in Pandas UDF#41147xinrong-meng wants to merge 5 commits intoapache:masterfrom
xinrong-meng wants to merge 5 commits intoapache:masterfrom
Conversation
xinrong-meng
commented
May 17, 2023
| return s | ||
|
|
||
| # To keep the current UDF behavior. | ||
| def _create_array(self, series, arrow_type): |
Member
Author
There was a problem hiding this comment.
Inherit _create_array of ArrowStreamPandasSerializer. After the change, it is consistent with createDataFrame from a pandas DataFrame when Arrow is enabled.
| return _convert_map_items_to_dict(s) | ||
| else: | ||
| return s | ||
| # TODO: cache the converter for reuse |
Member
There was a problem hiding this comment.
Could you file a JIRA issue officially and make this IDed TODO like TODO(SPARK-XXX)?
Member
Author
|
@ueshin @HyukjinKwon @zhengruifeng would you please review? |
ueshin
approved these changes
May 19, 2023
Member
Author
|
Merged to master, thank you! |
Member
Author
|
Please free to leave comments if any, I'll adjust them in follow-ups. |
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?
Fix nested MapType behavior in Pandas UDF (and Arrow-optimized Python UDF).
Previously during Arrow-pandas conversion, only the outermost layer is converted to a dictionary; but now nested MapType will be converted to nested dictionaries.
That applies to Spark Connect as well.
Why are the changes needed?
Correctness and consistency (with
createDataFrameandtoPandaswhen Arrow is enabled).Does this PR introduce any user-facing change?
Yes.
Nested MapType type support is corrected in Pandas UDF
The results of
df.select(f(df.attributes)).show(truncate=False)is correctedFROM
TO
Another more obvious example:
df.select(extract_name(df.attributes)).show(truncate=False)is correctedFROM
TO
How was this patch tested?
Unit tests.