code: def test_type_coercion_string_to_numeric(self):
      df_int_value = self.spark.createDataFrame(
          ["1", "2"], schema="string"
      )
      df_floating_value = self.spark.createDataFrame(
          ["1.1", "2.2"], schema="string"
      )
  
      int_ddl_types = ["tinyint", "smallint", "int", "bigint"]
      floating_ddl_types = ["double", "float"]
  
      for ddl_type in int_ddl_types:
          # df_int_value
          res = df_int_value.select(
              udf(lambda x: x, ddl_type)("value").alias("res")
          )
          self.assertEqual(res.collect(), [Row(res=1), Row(res=2)])
          self.assertEqual(res.dtypes[0][1], ddl_type)
  
      floating_results = [
          [Row(res=1.1), Row(res=2.2)],
          [Row(res=1.100000023841858), Row(res=2.200000047683716)],
      ]
      for ddl_type, floating_res in zip(
          floating_ddl_types, floating_results
      ):
          # df_int_value
          res = df_int_value.select(
              udf(lambda x: x, ddl_type)("value").alias("res")
          )
          self.assertEqual(res.collect(), [Row(res=1.0), Row(res=2.0)])
          self.assertEqual(res.dtypes[0][1], ddl_type)
          # df_floating_value
          res = df_floating_value.select(
              udf(lambda x: x, ddl_type)("value").alias("res")
          )
          self.assertEqual(res.collect(), floating_res)
          self.assertEqual(res.dtypes[0][1], ddl_type)
  
      # invalid
      with self.assertRaises(PythonException):
          df_floating_value.select(
              udf(lambda x: x, "int")("value").alias("res")
          ).collect()
  
      with self.assertRaises(PythonException):
          df_int_value.select(
              udf(lambda x: x, "decimal")("value").alias("res")
          ).collect()
  
      with self.assertRaises(PythonException):
          df_floating_value.select(
              udf(lambda x: x, "decimal")("value").alias("res")
          ).collect()
  
imports: import unittest
  from pyspark.errors import PythonException, PySparkNotImplementedError
  from pyspark.sql import Row
  from pyspark.sql.functions import udf
  from pyspark.sql.tests.test_udf import BaseUDFTestsMixin
  from pyspark.sql.types import VarcharType
  from pyspark.testing.sqlutils import have_pandas, have_pyarrow, pandas_requirement_message, pyarrow_requirement_message, ReusedSQLTestCase
  from pyspark.rdd import PythonEvalType
label_desc: Use image node_id 9 for calling the PythonUDFArrowTestsMixin obj's underlying member method code with example usage: obj.test_type_coercion_string_to_numeric() without return types