class_docstr: Serializer used by Python worker to evaluate Pandas UDFs
class_docstr_tok: ["Serializer","used","by","Python","worker","to","evaluate","Pandas","UDFs"]
docstr: Create an Arrow StructArray from the given pandas.DataFrame and arrow struct type.
  
  Parameters
  ----------
  df : pandas.DataFrame
      A pandas DataFrame
  arrow_struct_type : pyarrow.DataType
      pyarrow struct type
  
  Returns
  -------
  pyarrow.Array
code: def _create_struct_array(self, df, arrow_struct_type):
      """
      Create an Arrow StructArray from the given pandas.DataFrame and arrow struct type.
  
      Parameters
      ----------
      df : pandas.DataFrame
          A pandas DataFrame
      arrow_struct_type : pyarrow.DataType
          pyarrow struct type
  
      Returns
      -------
      pyarrow.Array
      """
      import pyarrow as pa
  
      if len(df.columns) == 0:
          return pa.array([{}] * len(df), arrow_struct_type)
      # Assign result columns by schema name if user labeled with strings
      if self._assign_cols_by_name and any(
          isinstance(name, str) for name in df.columns
      ):
          struct_arrs = [
              self._create_array(
                  df[field.name],
                  field.type,
                  arrow_cast=self._arrow_cast,
              )
              for field in arrow_struct_type
          ]
      # Assign result columns by position
      else:
          struct_arrs = [
              # the selected series has name '1', so we rename it to field.name
              # as the name is used by _create_array to provide a meaningful error message
              self._create_array(
                  df[df.columns[i]].rename(field.name),
                  field.type,
                  arrow_cast=self._arrow_cast,
              )
              for i, field in enumerate(arrow_struct_type)
          ]
  
      struct_names = [field.name for field in arrow_struct_type]
      return pa.StructArray.from_arrays(struct_arrs, struct_names)
  
imports: from pyspark.errors import PySparkRuntimeError, PySparkTypeError, PySparkValueError
  from pyspark.loose_version import LooseVersion
  from pyspark.serializers import Serializer, read_int, write_int, UTF8Deserializer, CPickleSerializer
  from pyspark.sql.pandas.types import from_arrow_type, to_arrow_type, _create_converter_from_pandas, _create_converter_to_pandas
  from pyspark.sql.types import DataType, StringType, StructType, BinaryType, StructField, LongType, IntegerType
label_desc: Use image node_id 3 for calling the ArrowStreamPandasUDFSerializer obj's underlying member method code with example usage: obj._create_struct_array(df, arrow_struct_type) and returns: pa, pa