class_docstr: Min-in for the conversion from pandas to Spark. Currently, only :class:`SparkSession`
  can use this class.
docstr: Convert a pandas.DataFrame to list of records that can be used to make a DataFrame
  
  Returns
  -------
  list
      list of records
docstr_tok: ["Convert","a","pandas.DataFrame","to","list","of","records","that","can","be","used","to","make","a","DataFrame","Returns","--","--","--","-","list","list","of","records"]
code: def _convert_from_pandas(
      self,
      pdf: "PandasDataFrameLike",
      schema: Union[StructType, str, List[str]],
      timezone: str,
  ) -> List:
      """
      Convert a pandas.DataFrame to list of records that can be used to make a DataFrame
  
      Returns
      -------
      list
          list of records
      """
      from pyspark.sql import SparkSession
  
      assert isinstance(self, SparkSession)
  
      if timezone is not None:
          from pyspark.sql.pandas.types import (
              _check_series_convert_timestamps_tz_local,
              _get_local_timezone,
          )
          import pandas as pd
          from pandas.core.dtypes.common import is_timedelta64_dtype
  
          copied = False
          if isinstance(schema, StructType):
  
              def _create_converter(
                  data_type: DataType,
              ) -> Callable[[pd.Series], pd.Series]:
                  if isinstance(data_type, TimestampType):
  
                      def correct_timestamp(
                          pser: pd.Series,
                      ) -> pd.Series:
                          return (
                              _check_series_convert_timestamps_tz_local(
                                  pser, timezone
                              )
                          )
  
                      return correct_timestamp
  
                  def _converter(
                      dt: DataType,
                  ) -> Optional[Callable[[Any], Any]]:
                      if isinstance(dt, ArrayType):
                          element_conv = _converter(dt.elementType) or (
                              lambda x: x
                          )
  
                          def convert_array(value: Any) -> Any:
                              if value is None:
                                  return None
                              else:
                                  return [
                                      element_conv(v) for v in value
                                  ]
  
                          return convert_array
  
                      elif isinstance(dt, MapType):
                          key_conv = _converter(dt.keyType) or (
                              lambda x: x
                          )
                          value_conv = _converter(dt.valueType) or (
                              lambda x: x
                          )
  
                          def convert_map(value: Any) -> Any:
                              if value is None:
                                  return None
                              else:
                                  return {
                                      key_conv(k): value_conv(v)
                                      for k, v in value.items()
                                  }
  
                          return convert_map
  
                      elif isinstance(dt, StructType):
                          field_names = dt.names
                          dedup_field_names = _dedup_names(field_names)
                          field_convs = [
                              _converter(f.dataType) or (lambda x: x)
                              for f in dt.fields
                          ]
  
                          def convert_struct(value: Any) -> Any:
                              if value is None:
                                  return None
                              elif isinstance(value, dict):
                                  _values = [
                                      field_convs[i](
                                          value.get(name, None)
                                      )
                                      for i, name in enumerate(
                                          dedup_field_names
                                      )
                                  ]
                                  return _create_row(
                                      field_names, _values
                                  )
                              else:
                                  _values = [
                                      field_convs[i](value[i])
                                      for i, name in enumerate(value)
                                  ]
                                  return _create_row(
                                      field_names, _values
                                  )
  
                          return convert_struct
  
                      elif isinstance(dt, TimestampType):
  
                          def convert_timestamp(value: Any) -> Any:
                              if value is None:
                                  return None
                              else:
                                  return (
                                      pd.Timestamp(value)
                                      .tz_localize(timezone, ambiguous=False)  # type: ignore
                                      .tz_convert(_get_local_timezone())
                                      .tz_localize(None)
                                      .to_pydatetime()
                                  )
  
                          return convert_timestamp
  
                      else:
                          return None
  
                  conv = _converter(data_type)
                  if conv is not None:
                      return lambda pser: pser.apply(conv)  # type: ignore[return-value]
                  else:
                      return lambda pser: pser
  
              if len(pdf.columns) > 0:
                  pdf = pd.concat(
                      [
                          _create_converter(field.dataType)(pser)
                          for (_, pser), field in zip(
                              pdf.items(), schema.fields
                          )
                      ],
                      axis="columns",
                  )
                  copied = True
          else:
              should_localize = not is_timestamp_ntz_preferred()
              for column, series in pdf.items():
                  s = series
                  if (
                      should_localize
                      and isinstance(s.dtype, pd.DatetimeTZDtype)
                      and s.dt.tz is not None
                  ):
                      s = _check_series_convert_timestamps_tz_local(
                          series, timezone
                      )
                  if s is not series:
                      if not copied:
                          # Copy once if the series is modified to prevent the original
                          # Pandas DataFrame from being updated
                          pdf = pdf.copy()
                          copied = True
                      pdf[column] = s
  
          for column, series in pdf.items():
              if is_timedelta64_dtype(series):
                  if not copied:
                      pdf = pdf.copy()
                      copied = True
                  # Explicitly set the timedelta as object so the output of numpy records can
                  # hold the timedelta instances as are. Otherwise, it converts to the internal
                  # numeric values.
                  ser = pdf[column]
                  pdf[column] = pd.Series(
                      ser.dt.to_pytimedelta(),
                      index=ser.index,
                      dtype="object",
                      name=ser.name,
                  )
  
      # Convert pandas.DataFrame to list of numpy records
      np_records = pdf.set_axis(
          [f"col_{i}" for i in range(len(pdf.columns))], axis="columns"  # type: ignore[arg-type]
      ).to_records(index=False)
  
      # Check if any columns need to be fixed for Spark to infer properly
      if len(np_records) > 0:
          record_dtype = self._get_numpy_record_dtype(np_records[0])
          if record_dtype is not None:
              return [
                  r.astype(record_dtype).tolist() for r in np_records
              ]
  
      # Convert list of numpy records to python lists
      return [r.tolist() for r in np_records]
  
imports: import sys
  from typing import Any, Callable, List, Optional, Union, no_type_check, overload, TYPE_CHECKING
  from warnings import warn
  from pyspark.errors.exceptions.captured import unwrap_spark_exception
  from pyspark.loose_version import LooseVersion
  from pyspark.rdd import _load_from_socket
  from pyspark.sql.pandas.serializers import ArrowCollectSerializer
  from pyspark.sql.pandas.types import _dedup_names
  from pyspark.sql.types import ArrayType, MapType, TimestampType, StructType, DataType, _create_row
  from pyspark.sql.utils import is_timestamp_ntz_preferred
  from pyspark.traceback_utils import SCCallSiteSync
  from pyspark.errors import PySparkTypeError
label_desc: Use image node_id 4 for calling the SparkConversionMixin obj's underlying member method code with example usage: obj._convert_from_pandas(pdf, schema, timezone) and returns: unknown, unknown, correct_timestamp, function, function, _check_series_convert_timestamps_tz_local, convert_array, convert_map, None, unknown, convert_struct, None, unknown, convert_timestamp, None, None, _create_row, _create_row, None, pd