File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -628,6 +628,20 @@ def convert_decimals_in_arrow_table(table, description) -> "pyarrow.Table":
628
628
return table
629
629
630
630
631
+ def datetime_parser (datetime_string ):
632
+ formats = ["%Y-%m-%d %H:%M:%S" , "%Y-%m-%d" ]
633
+
634
+ for fmt in formats :
635
+ try :
636
+ return datetime .datetime .strptime (datetime_string , fmt )
637
+ except ValueError :
638
+ continue
639
+
640
+ raise ValueError (
641
+ f"Datetime string '{ datetime_string } ' does not match any expected formats"
642
+ )
643
+
644
+
631
645
def convert_to_assigned_datatypes_in_column_table (column_table , description ):
632
646
633
647
converted_column_table = []
@@ -642,16 +656,7 @@ def convert_to_assigned_datatypes_in_column_table(column_table, description):
642
656
)
643
657
elif description [i ][1 ] == "timestamp" :
644
658
converted_column_table .append (
645
- tuple (
646
- (
647
- v
648
- if v is None
649
- else datetime .datetime .strptime (
650
- v , "%Y-%m-%d %H:%M:%S.%f"
651
- ).replace (tzinfo = pytz .UTC )
652
- )
653
- for v in col
654
- )
659
+ tuple ((v if v is None else datetime_parser (v )) for v in col )
655
660
)
656
661
else :
657
662
converted_column_table .append (col )
You can’t perform that action at this time.
0 commit comments