File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -1610,7 +1610,7 @@ def render_seed(self) -> t.Iterator[QueryOrDF]:
16101610 for column in [* date_columns , * datetime_columns ]:
16111611 import pandas as pd
16121612
1613- df [column ] = pd .to_datetime (df [column ])
1613+ df [column ] = pd .to_datetime (df [column ], infer_datetime_format = True , errors = "ignore" ) # type: ignore
16141614
16151615 # extract datetime.date from pandas timestamp for DATE columns
16161616 for column in date_columns :
Original file line number Diff line number Diff line change @@ -9917,6 +9917,31 @@ def test_seed_dont_coerce_na_into_null(tmp_path):
99179917 assert next (model .render (context = None )).to_dict () == {"code" : {0 : "NA" }}
99189918
99199919
9920+ def test_seed_coerce_datetime (tmp_path ):
9921+ model_csv_path = (tmp_path / "model.csv" ).absolute ()
9922+
9923+ with open (model_csv_path , "w" , encoding = "utf-8" ) as fd :
9924+ fd .write ("bad_datetime\n 9999-12-31 23:59:59" )
9925+
9926+ expressions = d .parse (
9927+ f"""
9928+ MODEL (
9929+ name db.seed,
9930+ kind SEED (
9931+ path '{ str (model_csv_path )} ',
9932+ ),
9933+ columns (
9934+ bad_datetime datetime,
9935+ ),
9936+ );
9937+ """
9938+ )
9939+
9940+ model = load_sql_based_model (expressions , path = Path ("./examples/sushi/models/test_model.sql" ))
9941+ df = next (model .render (context = None ))
9942+ assert df ["bad_datetime" ].iloc [0 ] == "9999-12-31 23:59:59"
9943+
9944+
99209945def test_missing_column_data_in_columns_key ():
99219946 expressions = d .parse (
99229947 """
You can’t perform that action at this time.
0 commit comments