-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23334][SQL][PYTHON] Fix pandas_udf with return type StringType() to handle str type properly in Python 2. #20507
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…rly.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3920,6 +3920,14 @@ def test_vectorized_udf_null_string(self): | |
| res = df.select(str_f(col('str'))) | ||
| self.assertEquals(df.collect(), res.collect()) | ||
|
|
||
| def test_vectorized_udf_string_in_udf(self): | ||
| from pyspark.sql.functions import pandas_udf, col | ||
| import pandas as pd | ||
| df = self.spark.range(10) | ||
| str_f = pandas_udf(lambda x: pd.Series(["%s" % i for i in x]), StringType()) | ||
|
||
| res = df.select(str_f(col('id'))) | ||
|
||
| self.assertEquals(df.select(col('id').cast('string')).collect(), res.collect()) | ||
|
|
||
| def test_vectorized_udf_datatype_string(self): | ||
| from pyspark.sql.functions import pandas_udf, col | ||
| df = self.spark.range(10).select( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
@ueshin, actually, how about
s.apply(lambda v: v.decode("utf-8") if isinstance(v, str) else v)to allow non-ascii encodable unicodes too likeu"아"? I was worried of performance but I ran a simple perf test vss.str.decode('utf-8')for sure. Seems actually fine.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.
Good catch! I'll take it. Thanks!