code: def check_apply_in_pandas_returning_incompatible_type(self):
      for safely in [True, False]:
          with self.subTest(
              convertToArrowArraySafely=safely
          ), self.sql_conf(
              {
                  "spark.sql.execution.pandas.convertToArrowArraySafely": safely
              }
          ):
              # sometimes we see ValueErrors
              with self.subTest(convert="string to double"):
                  expected = (
                      r"ValueError: Exception thrown when converting pandas.Series \(object\) "
                      r"with name 'k' to Arrow Array \(double\)."
                  )
                  if safely:
                      expected = expected + (
                          " It can be caused by overflows or other "
                          "unsafe conversions warned by Arrow. Arrow safe type check "
                          "can be disabled by using SQL config "
                          "`spark.sql.execution.pandas.convertToArrowArraySafely`."
                      )
                  self._test_merge_error(
                      fn=lambda lft, rgt: pd.DataFrame(
                          {"id": [1], "k": ["2.0"]}
                      ),
                      output_schema="id long, k double",
                      error_class=PythonException,
                      error_message_regex=expected,
                  )
  
              # sometimes we see TypeErrors
              with self.subTest(convert="double to string"):
                  expected = (
                      r"TypeError: Exception thrown when converting pandas.Series \(float64\) "
                      r"with name 'k' to Arrow Array \(string\).\n"
                  )
                  self._test_merge_error(
                      fn=lambda lft, rgt: pd.DataFrame(
                          {"id": [1], "k": [2.0]}
                      ),
                      output_schema="id long, k string",
                      error_class=PythonException,
                      error_message_regex=expected,
                  )
  
imports: import unittest
  from typing import cast
  from pyspark.sql.functions import array, explode, col, lit, udf, pandas_udf, sum
  from pyspark.sql.types import ArrayType, DoubleType, LongType, StructType, StructField, YearMonthIntervalType, Row
  from pyspark.sql.window import Window
  from pyspark.errors import IllegalArgumentException, PythonException
  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 23 for calling the CogroupedApplyInPandasTestsMixin obj's underlying member method code with example usage: obj.check_apply_in_pandas_returning_incompatible_type() without return types