xinrong-meng opened a new pull request, #41503:
URL: https://github.com/apache/spark/pull/41503
### What changes were proposed in this pull request?
Explicit Arrow casting for the mismatched return type of Pandas UDF and
Arrow-optimized Python UDF.
### Why are the changes needed?
A more standardized type coercion.
### Does this PR introduce _any_ user-facing change?
Yes.
FROM
```py
>>> df = spark.createDataFrame(['1', '2'], schema='string')
df.select(pandas_udf(lambda x: x, 'int')('value')).show()
>>> df.select(pandas_udf(lambda x: x, 'int')('value')).show()
...
org.apache.spark.api.python.PythonException: Traceback (most recent call
last):
...
pyarrow.lib.ArrowInvalid: Could not convert '1' with type str: tried to
convert to int32
```
TO
```py
>>> df = spark.createDataFrame(['1', '2'], schema='string')
>>> df.select(pandas_udf(lambda x: x, 'int')('value')).show()
+---------------+
|<lambda>(value)|
+---------------+
| 1|
| 2|
+---------------+
```
### How was this patch tested?
TODO
--
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]