code: def test_pandas_udf_detect_unsafe_type_conversion(self):
      import pandas as pd
      import numpy as np
  
      values = [1.0] * 3
      pdf = pd.DataFrame({"A": values})
      df = self.spark.createDataFrame(pdf).repartition(1)
  
      @pandas_udf(returnType="int")
      def udf(column):
          return pd.Series(np.linspace(0, 1, len(column)))
  
      # Since 0.11.0, PyArrow supports the feature to raise an error for unsafe cast.
      with self.sql_conf(
          {"spark.sql.execution.pandas.convertToArrowArraySafely": True}
      ):
          with self.assertRaisesRegex(
              Exception,
              "Exception thrown when converting pandas.Series",
          ):
              df.select(["A"]).withColumn("udf", udf("A")).collect()
  
      # Disabling Arrow safe type check.
      with self.sql_conf(
          {
              "spark.sql.execution.pandas.convertToArrowArraySafely": False
          }
      ):
          df.select(["A"]).withColumn("udf", udf("A")).collect()
  
imports: import unittest
  import datetime
  from typing import cast
  from pyspark.sql.functions import udf, pandas_udf, PandasUDFType, assert_true, lit
  from pyspark.sql.types import DoubleType, StructType, StructField, LongType, DayTimeIntervalType
  from pyspark.errors import ParseException, PythonException, PySparkTypeError
  from pyspark.rdd import PythonEvalType
  from pyspark.testing.sqlutils import ReusedSQLTestCase, have_pandas, have_pyarrow, pandas_requirement_message, pyarrow_requirement_message
  from pyspark.testing.utils import QuietTest
label_desc: Use image node_id 10 for calling the PandasUDFTestsMixin obj's underlying member method code with example usage: obj.test_pandas_udf_detect_unsafe_type_conversion() and returns: pd