gaogaotiantian opened a new pull request, #60581:
URL: https://github.com/apache/spark/pull/60581

   ### What changes were proposed in this pull request?
   
   Adds `test_invalid_return_type_for_arrow_and_pandas_apis` to 
`BaseUDFTestsMixin` in `python/pyspark/sql/tests/test_udf.py`. It checks that 
each of these APIs rejects an invalid return type when the plan is built:
   
   - `udf(..., useArrow=True)` with a type Arrow cannot represent 
(`YearMonthIntervalType`) raises `PySparkNotImplementedError`.
   - `DataFrame.mapInArrow` with a struct containing an unsupported field 
raises `PySparkNotImplementedError`. `DataFrame.mapInPandas` with a non-struct 
schema raises `INVALID_RETURN_TYPE_FOR_PANDAS_UDF`.
   - `GroupedData.applyInArrow` raises `PySparkNotImplementedError` for an 
unsupported field and `INVALID_RETURN_TYPE_FOR_ARROW_UDF` for a non-struct 
schema.
   - `PandasCogroupedOps.applyInPandas` with a non-struct schema raises 
`INVALID_RETURN_TYPE_FOR_PANDAS_UDF`.
   - `PandasCogroupedOps.applyInArrow` raises `PySparkNotImplementedError` for 
an unsupported field and `INVALID_RETURN_TYPE_FOR_ARROW_UDF` for a non-struct 
schema.
   
   No Spark job runs. The test is skipped when pandas or pyarrow is missing.
   
   ### Why are the changes needed?
   
   12 lines of `UserDefinedFunction._check_return_type` in 
`python/pyspark/sql/udf.py` were not covered by any test. These are the error 
branches for Arrow-optimized Python UDFs, map-in-Arrow/Pandas, grouped-map 
Arrow, and cogrouped-map Pandas/Arrow return types. This adds coverage for all 
12.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No, test-only change.
   
   ### How was this patch tested?
   
   Ran in the PySpark CI image:
   
   - `python/run-tests --testnames 'pyspark.sql.tests.test_udf UDFTests'` 
(whole class, 93 tests): passed.
   - `python/run-tests --testnames 'pyspark.sql.tests.connect.test_parity_udf 
UDFParityTests.test_invalid_return_type_for_arrow_and_pandas_apis'`: passed.
   - `ruff check` and `ruff format --check` on the changed file: passed.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 5.5)
   
   This pull request and its description were written by Isaac.


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