title: Pyspark dataframe data type for all columns changed to String by UDF
body: <p>I have  a dataframe which have few columns like email_address(String), paid(integer) and date(datetime type)</p>
  
  <p>I'm running a UDF as mentioned below:</p>
  
  <pre><code>from pyspark.sql.functions import udf, col
  
  def conv(column):
      date_format='%m/%d/%Y'
      a = None
      if column:
          try:
              a= datetime.strptime(str(column),'%Y-%m-%d').strftime(date_format)
              print("Inside Try")
          except:
              a = column
              print("Inside except")
      return a
  
  conv_func = udf(conv)
  
  df_new = date_df.select(*(conv_func(col(c)).alias(c) for c in date_df.columns))
  </code></pre>
  
  <p>So in df_new I'm expecting email_address(<strong>String</strong>), paid(<strong>integer</strong>) and date(<strong>string</strong>) with changed format from YYYY-MM-DD to MM/DD/YYYY .</p>
  
  <p>The problem is UDF does converts the format but also changes the datatype of <strong>paid column to string from integer</strong> which I didn't anticipated for.</p>
  
  <p>I wonder how to avoid that using this UDF.</p>