Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-22417

createDataFrame from a pandas.DataFrame reads datetime64 values as longs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.2.0
    • 2.2.1, 2.3.0
    • PySpark
    • None

    Description

      When trying to create a Spark DataFrame from an existing Pandas DataFrame using createDataFrame, columns with datetime64 values are converted as long values. This is only when the schema is not specified.

      In [2]: import pandas as pd
         ...: from datetime import datetime
         ...: 
      
      In [3]: pdf = pd.DataFrame({"ts": [datetime(2017, 10, 31, 1, 1, 1)]})
      
      In [4]: df = spark.createDataFrame(pdf)
      
      In [5]: df.show()
      +-------------------+
      |                 ts|
      +-------------------+
      |1509411661000000000|
      +-------------------+
      
      
      In [6]: df.schema
      Out[6]: StructType(List(StructField(ts,LongType,true)))
      

      Spark should interpret a datetime64[D] value to DateType and other datetime64 values to TImestampType.

      Attachments

        Issue Links

          Activity

            People

              bryanc Bryan Cutler
              bryanc Bryan Cutler
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: