File tree Expand file tree Collapse file tree
src/datacustomcode/io/reader Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434
3535from datacustomcode .credentials import Credentials
3636from datacustomcode .io .reader .base import BaseDataCloudReader
37+ import pandas .api .types as pd_types
3738
3839if TYPE_CHECKING :
3940 import pandas
4849 "object" : StringType (),
4950 "int64" : LongType (),
5051 "float64" : DoubleType (),
51- "datetime64[ns]" : TimestampType (),
52- "datetime64[ns, UTC]" : TimestampType (),
53- "datetime64[ms]" : TimestampType (),
54- "datetime64[ms, UTC]" : TimestampType (),
5552 "bool" : BooleanType (),
5653}
5754
@@ -61,7 +58,10 @@ def _pandas_to_spark_schema(
6158) -> StructType :
6259 fields = []
6360 for column , dtype in pandas_df .dtypes .items ():
64- spark_type = PANDAS_TYPE_MAPPING .get (str (dtype ), StringType ())
61+ if pd_types .is_datetime64_any_dtype (dtype ):
62+ spark_type = TimestampType ()
63+ else :
64+ spark_type = PANDAS_TYPE_MAPPING .get (str (dtype ), StringType ())
6565 fields .append (StructField (column , spark_type , nullable ))
6666 return StructType (fields )
6767
You can’t perform that action at this time.
0 commit comments