class_docstr: User defined function in Python
  
  .. versionadded:: 1.3
  
  Notes
  -----
  The constructor of this class is not supposed to be directly called.
  Use :meth:`pyspark.sql.functions.udf` or :meth:`pyspark.sql.functions.pandas_udf`
  to create this instance.
class_docstr_tok: ["User","defined","function","in","Python","..","versionadded",":",":","1.3","Notes","--","--","-","The","constructor","of","this","class","is","not","supposed","to","be","directly","called",".","Use",":","meth",":","`","pyspark.sql.functions.udf","`","or",":","meth",":","`","pyspark.sql.functions.pandas_udf","`","to","create","this","instance","."]
code: def returnType(self) -> DataType:
      # This makes sure this is called after SparkContext is initialized.
      # ``_parse_datatype_string`` accesses to JVM for parsing a DDL formatted string.
      # TODO: PythonEvalType.SQL_BATCHED_UDF
      if self._returnType_placeholder is None:
          if isinstance(self._returnType, DataType):
              self._returnType_placeholder = self._returnType
          else:
              self._returnType_placeholder = _parse_datatype_string(
                  self._returnType
              )
      if self.evalType == PythonEvalType.SQL_ARROW_BATCHED_UDF:
          try:
              to_arrow_type(self._returnType_placeholder)
          except TypeError:
              raise PySparkNotImplementedError(
                  error_class="NOT_IMPLEMENTED",
                  message_parameters={
                      "feature": f"Invalid return type with Arrow-optimized Python UDF: "
                      f"{self._returnType_placeholder}"
                  },
              )
      elif (
          self.evalType == PythonEvalType.SQL_SCALAR_PANDAS_UDF
          or self.evalType == PythonEvalType.SQL_SCALAR_PANDAS_ITER_UDF
      ):
          try:
              to_arrow_type(self._returnType_placeholder)
          except TypeError:
              raise PySparkNotImplementedError(
                  error_class="NOT_IMPLEMENTED",
                  message_parameters={
                      "feature": f"Invalid return type with scalar Pandas UDFs: "
                      f"{self._returnType_placeholder}"
                  },
              )
      elif (
          self.evalType == PythonEvalType.SQL_GROUPED_MAP_PANDAS_UDF
          or self.evalType
          == PythonEvalType.SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE
      ):
          if isinstance(self._returnType_placeholder, StructType):
              try:
                  to_arrow_type(self._returnType_placeholder)
              except TypeError:
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": f"Invalid return type with grouped map Pandas UDFs or "
                          f"at groupby.applyInPandas(WithState): {self._returnType_placeholder}"
                      },
                  )
          else:
              raise PySparkTypeError(
                  error_class="INVALID_RETURN_TYPE_FOR_PANDAS_UDF",
                  message_parameters={
                      "eval_type": "SQL_GROUPED_MAP_PANDAS_UDF or "
                      "SQL_GROUPED_MAP_PANDAS_UDF_WITH_STATE",
                      "return_type": str(self._returnType_placeholder),
                  },
              )
      elif (
          self.evalType == PythonEvalType.SQL_MAP_PANDAS_ITER_UDF
          or self.evalType == PythonEvalType.SQL_MAP_ARROW_ITER_UDF
      ):
          if isinstance(self._returnType_placeholder, StructType):
              try:
                  to_arrow_type(self._returnType_placeholder)
              except TypeError:
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": f"Invalid return type in mapInPandas: "
                          f"{self._returnType_placeholder}"
                      },
                  )
          else:
              raise PySparkTypeError(
                  error_class="INVALID_RETURN_TYPE_FOR_PANDAS_UDF",
                  message_parameters={
                      "eval_type": "SQL_MAP_PANDAS_ITER_UDF or SQL_MAP_ARROW_ITER_UDF",
                      "return_type": str(self._returnType_placeholder),
                  },
              )
      elif self.evalType == PythonEvalType.SQL_GROUPED_MAP_ARROW_UDF:
          if isinstance(self._returnType_placeholder, StructType):
              try:
                  to_arrow_type(self._returnType_placeholder)
              except TypeError:
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": "Invalid return type with grouped map Arrow UDFs or "
                          f"at groupby.applyInArrow: {self._returnType_placeholder}"
                      },
                  )
          else:
              raise PySparkTypeError(
                  error_class="INVALID_RETURN_TYPE_FOR_ARROW_UDF",
                  message_parameters={
                      "eval_type": "SQL_GROUPED_MAP_ARROW_UDF",
                      "return_type": str(self._returnType_placeholder),
                  },
              )
      elif self.evalType == PythonEvalType.SQL_COGROUPED_MAP_PANDAS_UDF:
          if isinstance(self._returnType_placeholder, StructType):
              try:
                  to_arrow_type(self._returnType_placeholder)
              except TypeError:
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": f"Invalid return type in cogroup.applyInPandas: "
                          f"{self._returnType_placeholder}"
                      },
                  )
          else:
              raise PySparkTypeError(
                  error_class="INVALID_RETURN_TYPE_FOR_PANDAS_UDF",
                  message_parameters={
                      "eval_type": "SQL_COGROUPED_MAP_PANDAS_UDF",
                      "return_type": str(self._returnType_placeholder),
                  },
              )
      elif self.evalType == PythonEvalType.SQL_COGROUPED_MAP_ARROW_UDF:
          if isinstance(self._returnType_placeholder, StructType):
              try:
                  to_arrow_type(self._returnType_placeholder)
              except TypeError:
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": "Invalid return type in cogroup.applyInArrow: "
                          f"{self._returnType_placeholder}"
                      },
                  )
          else:
              raise PySparkTypeError(
                  error_class="INVALID_RETURN_TYPE_FOR_ARROW_UDF",
                  message_parameters={
                      "eval_type": "SQL_COGROUPED_MAP_ARROW_UDF",
                      "return_type": str(self._returnType_placeholder),
                  },
              )
      elif self.evalType == PythonEvalType.SQL_GROUPED_AGG_PANDAS_UDF:
          try:
              # StructType is not yet allowed as a return type, explicitly check here to fail fast
              if isinstance(self._returnType_placeholder, StructType):
                  raise PySparkNotImplementedError(
                      error_class="NOT_IMPLEMENTED",
                      message_parameters={
                          "feature": f"Invalid return type with grouped aggregate Pandas UDFs: "
                          f"{self._returnType_placeholder}"
                      },
                  )
              to_arrow_type(self._returnType_placeholder)
          except TypeError:
              raise PySparkNotImplementedError(
                  error_class="NOT_IMPLEMENTED",
                  message_parameters={
                      "feature": f"Invalid return type with grouped aggregate Pandas UDFs: "
                      f"{self._returnType_placeholder}"
                  },
              )
  
      return self._returnType_placeholder
  
imports: from inspect import getfullargspec
  import functools
  import inspect
  import sys
  import warnings
  from typing import Callable, Any, TYPE_CHECKING, Optional, cast, Union
  from py4j.java_gateway import JavaObject
  from pyspark import SparkContext
  from pyspark.rdd import _prepare_for_python_RDD, PythonEvalType
  from pyspark.sql.column import Column, _to_java_expr, _to_seq
  from pyspark.sql.types import DataType, StringType, StructType, _parse_datatype_string
  from pyspark.sql.utils import get_active_spark_context
  from pyspark.sql.pandas.types import to_arrow_type
  from pyspark.sql.pandas.utils import require_minimum_pandas_version, require_minimum_pyarrow_version
  from pyspark.errors import PySparkTypeError, PySparkNotImplementedError, PySparkRuntimeError
label_desc: Use image node_id 2 for calling the UserDefinedFunction obj's underlying member method code with example usage: obj.returnType() and returns: self