-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24324][PYTHON] Pandas Grouped Map UDF should assign result columns by name #21427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
21e0c3e
bbe3587
a653e9b
88e2aa3
7cc0c49
d4b5da1
63c3963
9bbf014
74c5d8e
b2d0966
5a7edb2
59972d6
27b4cad
c593650
2d2ced6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ | |
| from pyspark.util import _get_argspec, fail_on_stopiteration | ||
| from pyspark import shuffle | ||
|
|
||
| if sys.version >= '3': | ||
| basestring = str | ||
|
|
||
| pickleSer = PickleSerializer() | ||
| utf8_deserializer = UTF8Deserializer() | ||
|
|
||
|
|
@@ -110,7 +113,16 @@ def wrapped(key_series, value_series): | |
| "Number of columns of the returned pandas.DataFrame " | ||
| "doesn't match specified schema. " | ||
| "Expected: {} Actual: {}".format(len(return_type), len(result.columns))) | ||
| return [(result[field.name], to_arrow_type(field.dataType)) for field in return_type] | ||
| try: | ||
| # Assign result columns by schema name | ||
| return [(result[field.name], to_arrow_type(field.dataType)) for field in return_type] | ||
| except KeyError: | ||
| if all(not isinstance(name, basestring) for name in result.columns): | ||
| # Assign result columns by position if they are not named with strings | ||
| return [(result[result.columns[i]], to_arrow_type(field.dataType)) | ||
| for i, field in enumerate(return_type)] | ||
| else: | ||
| raise | ||
|
||
|
|
||
| return wrapped | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do
isinstance(name, str)here to deal with python2/3?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe he's trying to deal with
unicodecase too just in python 2.isinstance(name, basestring)should be safer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we still need to check for the possibility that python 2 uses unicode.