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_r261303303
##########
File path: python/pyspark/serializers.py
##########
@@ -295,7 +297,33 @@ 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)))
+
+ # Assign result columns by schema name if user labeled with
strings, else use position
+ struct_arrs = []
+ struct_names = []
+ if assign_cols_by_name and any(isinstance(name, basestring) for
name in s.columns):
Review comment:
Yeah, this is copied from grouped map wrap. It didn't seem necessary to
check all columns to be string. The only case that ends up weird is if the
columns have a mix of strings and other types. I think that would be a little
strange and I'm not sure that assigning by position is the right thing to do.
So this would probably end up with raising a `KeyError` so that the user can
fix it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]