mengxr commented on a change in pull request #24643:
[SPARK-26412][PySpark][SQL] Allow Pandas UDF to take an iterator of pd.Series
or an iterator of tuple of pd.Series
URL: https://github.com/apache/spark/pull/24643#discussion_r293602500
##########
File path: python/pyspark/sql/tests/test_pandas_udf_scalar.py
##########
@@ -294,16 +349,23 @@ def test_vectorized_udf_struct_complex(self):
StructField('arr', ArrayType(LongType()))])
@pandas_udf(returnType=return_type)
- def f(id):
+ def scalar_f(id):
return pd.DataFrame({'ts': id.apply(lambda i: pd.Timestamp(i)),
'arr': id.apply(lambda i: [i, i + 1])})
- actual = df.withColumn('f', f(col('id'))).collect()
- for i, row in enumerate(actual):
- id, f = row
- self.assertEqual(i, id)
- self.assertEqual(pd.Timestamp(i).to_pydatetime(), f[0])
- self.assertListEqual([i, i + 1], f[1])
+ @pandas_udf(returnType=return_type,
functionType=PandasUDFType.SCALAR_ITER)
+ def iter_f(it):
+ for id in it:
+ yield pd.DataFrame({'ts': id.apply(lambda i: pd.Timestamp(i)),
Review comment:
minor: Can reuse the code if we don't wrap`@pandas_udf` for the scalar UDF.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]