EnricoMi commented on code in PR #39952:
URL: https://github.com/apache/spark/pull/39952#discussion_r1247662681


##########
python/pyspark/worker.py:
##########
@@ -133,65 +134,103 @@ def verify_result_length(result, length):
     )
 
 
-def wrap_batch_iter_udf(f, return_type):
+def wrap_batch_iter_udf(f, return_type, is_arrow_iter=False):
     arrow_return_type = to_arrow_type(return_type)
+    iter_type_label = (
+        "pyarrow.RecordBatch"
+        if is_arrow_iter
+        else ("pandas.DataFrame" if type(return_type) == StructType else 
"pandas.Series")
+    )
 
-    def verify_result_type(result):
-        if not hasattr(result, "__len__"):
-            pd_type = "Pandas.DataFrame" if type(return_type) == StructType 
else "Pandas.Series"
+    def verify_result(result):
+        if not isinstance(result, Iterator) and not hasattr(result, 
"__iter__"):
             raise TypeError(
                 "Return type of the user-defined function should be "
-                "{}, but is {}".format(pd_type, type(result))
+                "iterator of {}, but is {}".format(iter_type_label, 
type(result))
             )
         return result
 
+    def verify_element(elem):
+        if is_arrow_iter:
+            import pyarrow as pa
+
+            if not isinstance(elem, pa.RecordBatch):
+                raise TypeError(
+                    "Return type of the user-defined function should be "
+                    "iterator of {}, but is iterator of 
{}".format(iter_type_label, type(elem))
+                )
+        else:
+            import pandas as pd
+
+            if not isinstance(elem, pd.DataFrame if type(return_type) == 
StructType else pd.Series):
+                raise TypeError(

Review Comment:
   Sure, but the whole file uses `TypedError` instead of the new 
`PySparkTypeError`.
   
   I'd rather fix that in a separate PR and not fixing unrelated code in this 
PR.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to