You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/03/05 02:54:25 UTC
[GitHub] [spark] BryanCutler commented on a change in pull request #23900:
[SPARK-23836][PYTHON] Add support for StructType return in Scalar Pandas UDF
BryanCutler commented on a change in pull request #23900: [SPARK-23836][PYTHON] Add support for StructType return in Scalar Pandas UDF
URL: https://github.com/apache/spark/pull/23900#discussion_r262330285
##########
File path: python/pyspark/serializers.py
##########
@@ -295,7 +297,34 @@ def create_array(s, t):
raise RuntimeError(error_msg % (s.dtype, t), e)
return array
- arrs = [create_array(s, t) for s, t in series]
+ arrs = []
+ for s, t in series:
+ if t is not None and pa.types.is_struct(t):
+ if not isinstance(s, pd.DataFrame):
+ raise ValueError("A field of type StructType expects a pandas.DataFrame, "
+ "but got: %s" % str(type(s)))
+
+ # Input partition and result pandas.DataFrame empty, make empty Arrays with struct
+ if len(s) == 0 and len(s.columns) == 0:
Review comment:
I came across a case where there was an empty partition and when the udf processed it, the result is an empty Pandas DataFrame with no columns, see https://github.com/apache/spark/pull/23900/files#diff-d1bd0bd4ceeedd30cc219293a75ad90fR395
I figured it would be pretty confusing for the user to handle these kind of cases, and it's pretty simple to just check and add an empty struct when this happens, so that's what this check is for.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org