Skip to content

Commit 39a4cad

Browse files
committed
Apply TimestampType to any datetime64 detected
1 parent 641b6f8 commit 39a4cad

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/datacustomcode/io/reader/query_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from datacustomcode.credentials import Credentials
3636
from datacustomcode.io.reader.base import BaseDataCloudReader
37+
import pandas.api.types as pd_types
3738

3839
if TYPE_CHECKING:
3940
import pandas
@@ -48,10 +49,6 @@
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

0 commit comments

Comments
 (0)